diff --git a/.gitignore b/.gitignore index 67697151..ca36f06e 100644 --- a/.gitignore +++ b/.gitignore @@ -404,4 +404,4 @@ ASALocalRun/ # Local History for Visual Studio .localhistory/ - +CommBank-Server/Secrets.json \ No newline at end of file diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj index 983cc882..5d76d035 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server/CommBank.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable CommBank_Server diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..81f01923 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -11,6 +11,8 @@ public class Goal public string? Name { get; set; } + public string? Icon { get; set; } + public UInt64 TargetAmount { get; set; } = 0; public DateTime TargetDate { get; set; } diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs index a88e560d..24a3005d 100644 --- a/CommBank-Server/Program.cs +++ b/CommBank-Server/Program.cs @@ -1,4 +1,4 @@ -using CommBank.Models; +using CommBank.Models; using CommBank.Services; using MongoDB.Driver; @@ -12,7 +12,7 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json"); var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank")); -var mongoDatabase = mongoClient.GetDatabase("CommBank"); +var mongoDatabase = mongoClient.GetDatabase("commbank"); IAccountsService accountsService = new AccountsService(mongoDatabase); IAuthService authService = new AuthService(mongoDatabase); diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json deleted file mode 100644 index 0e5bf949..00000000 --- a/CommBank-Server/Secrets.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" - } -} \ No newline at end of file diff --git a/CommBank-Server/Services/GoalService.cs b/CommBank-Server/Services/GoalService.cs index b0c600a1..b07b0c19 100644 --- a/CommBank-Server/Services/GoalService.cs +++ b/CommBank-Server/Services/GoalService.cs @@ -1,4 +1,4 @@ -using CommBank.Models; +using CommBank.Models; using MongoDB.Driver; namespace CommBank.Services; @@ -9,7 +9,7 @@ public class GoalsService : IGoalsService public GoalsService(IMongoDatabase mongoDatabase) { - _goalsCollection = mongoDatabase.GetCollection("Goals"); + _goalsCollection = mongoDatabase.GetCollection("goals"); } public async Task> GetAsync() => diff --git a/CommBank-Server/appsettings.json b/CommBank-Server/appsettings.json index af0538f7..ac16883a 100644 --- a/CommBank-Server/appsettings.json +++ b/CommBank-Server/appsettings.json @@ -1,10 +1,16 @@ -{ +{ + "GoalDatabase": { + "ConnectionString": "mongodb+srv://raghavthaman:@cluster0.lkpodul.mongodb.net/?appName=Cluster0", + "DatabaseName": "commbank", + "GoalsCollectionName": "goals" + }, + "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/CommBank.Tests/CommBank.Tests.csproj b/CommBank.Tests/CommBank.Tests.csproj index 4d9413f4..3da571e3 100644 --- a/CommBank.Tests/CommBank.Tests.csproj +++ b/CommBank.Tests/CommBank.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..02e82813 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -1,4 +1,4 @@ -using CommBank.Controllers; +using CommBank.Controllers; using CommBank.Services; using CommBank.Models; using CommBank.Tests.Fake; @@ -66,9 +66,29 @@ public async void Get() public async void GetForUser() { // Arrange - + var testGoal = new Goal + { + Id = "test_id", + Name = "Tesla Model Y", + Icon = "🚗", + TargetAmount = 60000 + }; + var goals = new List { testGoal }; + var users = collections.GetUsers(); + IGoalsService goalsService = new FakeGoalsService(goals, testGoal); + IUsersService usersService = new FakeUsersService(users, users[0]); + GoalController controller = new(goalsService, usersService); + // Act - + var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext(); + controller.ControllerContext.HttpContext = httpContext; + var result = await controller.GetForUser("user_id"); + // Assert + Assert.NotNull(result); + var returnedGoal = Assert.Single(result); + Assert.Equal("Tesla Model Y", returnedGoal.Name); + Assert.Equal("🚗", returnedGoal.Icon); + Assert.Equal((ulong)60000, returnedGoal.TargetAmount); } } \ No newline at end of file diff --git a/pull_request.txt b/pull_request.txt new file mode 100644 index 00000000..8a9eea9d --- /dev/null +++ b/pull_request.txt @@ -0,0 +1 @@ +https://github.com/RaghavThaman/commbank-server/pull/1