Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Goal
public string? Id { get; set; }

public string? Name { get; set; }

public string? Icon { get; set; }

public UInt64 TargetAmount { get; set; } = 0;

Expand All @@ -27,4 +29,4 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }
}
}
25 changes: 18 additions & 7 deletions CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoDatabase = mongoClient.GetDatabase("CommBank");
var database = mongoClient.GetDatabase("CommBank");

IAccountsService accountsService = new AccountsService(mongoDatabase);
IAuthService authService = new AuthService(mongoDatabase);
IGoalsService goalsService = new GoalsService(mongoDatabase);
ITagsService tagsService = new TagsService(mongoDatabase);
ITransactionsService transactionsService = new TransactionsService(mongoDatabase);
IUsersService usersService = new UsersService(mongoDatabase);
IAccountsService accountsService = new AccountsService(database);
IAuthService authService = new AuthService(database);
IGoalsService goalsService = new GoalsService(database);
ITagsService tagsService = new TagsService(database);
ITransactionsService transactionsService = new TransactionsService(database);
IUsersService usersService = new UsersService(database);

builder.Services.AddSingleton(database); // Add mongo database to DI container

builder.Services.AddSingleton(accountsService);
builder.Services.AddSingleton(authService);
Expand All @@ -32,6 +34,15 @@

var app = builder.Build();

// Seed database with sample goals if empty
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var mongoDatabase = services.GetRequiredService<IMongoDatabase>();
var seeder = new CommBank.Seeding.SeedGoals(mongoDatabase);
seeder.SeedAsync().GetAwaiter().GetResult();
}

app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
Expand Down
6 changes: 3 additions & 3 deletions CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
{
"ConnectionStrings": {
"CommBank": "{CONNECTION_STRING}"
"CommBank":"mongodb+srv://vamsikrishnabathala1_db_user:[email protected]/"
}
}
}
1 change: 0 additions & 1 deletion CommBank-Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
},
"AllowedHosts": "*"
}