diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..59f39ee 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -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; @@ -27,4 +29,4 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } -} \ No newline at end of file +} diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs index a88e560..30fd82f 100644 --- a/CommBank-Server/Program.cs +++ b/CommBank-Server/Program.cs @@ -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); @@ -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(); + var seeder = new CommBank.Seeding.SeedGoals(mongoDatabase); + seeder.SeedAsync().GetAwaiter().GetResult(); +} + app.UseCors(builder => builder .AllowAnyOrigin() .AllowAnyMethod() diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf94..8b6f2b0 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ -{ +{ "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "CommBank":"mongodb+srv://vamsikrishnabathala1_db_user:rpcE0oD4caCmYB79@commonbank.x6fdftv.mongodb.net/" } -} \ No newline at end of file +} diff --git a/CommBank-Server/appsettings.json b/CommBank-Server/appsettings.json index af0538f..2230277 100644 --- a/CommBank-Server/appsettings.json +++ b/CommBank-Server/appsettings.json @@ -7,4 +7,3 @@ }, "AllowedHosts": "*" } -