From d5c72187489f23d56e64d20226a1926e159493d8 Mon Sep 17 00:00:00 2001 From: Richard <155915123+richardhamwi@users.noreply.github.com> Date: Tue, 21 Oct 2025 19:30:01 +1100 Subject: [PATCH] Support icons --- CommBank-Server/CommBank.csproj | 4 ++-- CommBank-Server/Controllers/GoalController.cs | 9 ++++++++ CommBank-Server/Models/Goal.cs | 2 ++ CommBank-Server/Secrets.json | 2 +- CommBank.Tests/GoalControllerTests.cs | 23 ++++++++++++++++--- Server.sln | 10 ++++++-- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj index 983cc88..0613ea1 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server/CommBank.csproj @@ -6,6 +6,7 @@ enable CommBank_Server CommBank-Server + 273e48ab-d4aa-4a94-9ef6-a9e18a643262 @@ -13,7 +14,7 @@ - + @@ -30,6 +31,5 @@ - diff --git a/CommBank-Server/Controllers/GoalController.cs b/CommBank-Server/Controllers/GoalController.cs index 98271a5..8b6052d 100644 --- a/CommBank-Server/Controllers/GoalController.cs +++ b/CommBank-Server/Controllers/GoalController.cs @@ -78,7 +78,16 @@ public async Task Update(string id, Goal updatedGoal) return NotFound(); } + // Preserve existing values, only update what was provided updatedGoal.Id = goal.Id; + updatedGoal.Name ??= goal.Name; + updatedGoal.TargetAmount = updatedGoal.TargetAmount == 0 ? goal.TargetAmount : updatedGoal.TargetAmount; + updatedGoal.TargetDate = updatedGoal.TargetDate == default ? goal.TargetDate : updatedGoal.TargetDate; + updatedGoal.Balance = updatedGoal.Balance == 0 ? goal.Balance : updatedGoal.Balance; + updatedGoal.Created = goal.Created; + updatedGoal.TransactionIds ??= goal.TransactionIds; + updatedGoal.TagIds ??= goal.TagIds; + updatedGoal.UserId ??= goal.UserId; await _goalsService.UpdateAsync(id, updatedGoal); diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..4fbeb14 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -27,4 +27,6 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } + + public string? Icon {get; set; } } \ No newline at end of file diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf94..d616016 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "CommBank": "mongodb+srv://richhamwi:JrEKzJBM9CLDMrs7@cluster0.favm3lk.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0" } } \ No newline at end of file diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..2670092 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -65,10 +65,27 @@ public async void Get() [Fact] public async void GetForUser() { - // Arrange - + var goals = collections.GetGoals(); + var users = collections.GetUsers(); + IGoalsService goalsService = new FakeGoalsService(goals, goals[0]); + 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(goals[0].UserId!); + // Assert + Assert.NotNull(result); + + var index = 0; + foreach (Goal goal in result!) + { + Assert.IsAssignableFrom(goal); + Assert.Equal(goals[0].UserId, goal.UserId); + index++; + } + } } \ No newline at end of file diff --git a/Server.sln b/Server.sln index 326f984..ea11a46 100644 --- a/Server.sln +++ b/Server.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 25.0.1700.1 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36414.22 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommBank", "CommBank-Server\CommBank.csproj", "{8CA79A33-1C65-4E35-8C43-E5D7D86F91BE}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommBank.Tests", "CommBank.Tests\CommBank.Tests.csproj", "{7402BDB7-7021-4C7C-AEF4-F592FB605913}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dBtest", "dBtest\dBtest.csproj", "{3064B5FC-1F59-4B73-AA5A-01511648D9E4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {7402BDB7-7021-4C7C-AEF4-F592FB605913}.Debug|Any CPU.Build.0 = Debug|Any CPU {7402BDB7-7021-4C7C-AEF4-F592FB605913}.Release|Any CPU.ActiveCfg = Release|Any CPU {7402BDB7-7021-4C7C-AEF4-F592FB605913}.Release|Any CPU.Build.0 = Release|Any CPU + {3064B5FC-1F59-4B73-AA5A-01511648D9E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3064B5FC-1F59-4B73-AA5A-01511648D9E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3064B5FC-1F59-4B73-AA5A-01511648D9E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3064B5FC-1F59-4B73-AA5A-01511648D9E4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE