diff --git a/.gitignore b/.gitignore index 67697151..49302c74 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ test-results/ *.app # content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore -# General + .DS_Store .AppleDouble .LSOverride @@ -405,3 +405,15 @@ ASALocalRun/ .localhistory/ +.env +.env.local +.env.*.local + +Secrets.json + +# Test/Mock Data Files +getAll.json +getId.json +getId_withIcon.json + + diff --git a/CommBank-Server/Controllers/GoalController.cs b/CommBank-Server/Controllers/GoalController.cs index 98271a5f..f8a27a71 100644 --- a/CommBank-Server/Controllers/GoalController.cs +++ b/CommBank-Server/Controllers/GoalController.cs @@ -85,6 +85,23 @@ public async Task Update(string id, Goal updatedGoal) return NoContent(); } + [HttpPut("{id:length(24)}/icon")] + public async Task UpdateIcon(string id, [FromBody] UpdatedIcon updatedIcon) + { + var goal = await _goalsService.GetAsync(id); + + if (goal is null) + { + return NotFound(); + } + + goal.Icon = updatedIcon.Icon; + + await _goalsService.UpdateAsync(id, goal); + + return NoContent(); + } + [HttpDelete("{id:length(24)}")] public async Task Delete(string id) { diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..20b9b5d4 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 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.Tests/Fake/FakeCollections.cs b/CommBank.Tests/Fake/FakeCollections.cs index 28452832..b40ddf7b 100644 --- a/CommBank.Tests/Fake/FakeCollections.cs +++ b/CommBank.Tests/Fake/FakeCollections.cs @@ -33,19 +33,22 @@ public FakeCollections() new() { Id = "1", - Name = "House Down Payment" + Name = "House Down Payment", + UserId = "1" }, new() { Id = "2", - Name = "Tesla Model Y" + Name = "Tesla Model Y", + UserId = "1" }, new() { Id = "3", - Name = "Trip to London" + Name = "Trip to London", + UserId = "2" }, }; diff --git a/CommBank.Tests/Fake/FakeGoalsService.cs b/CommBank.Tests/Fake/FakeGoalsService.cs index 643a27e6..603ec2a0 100644 --- a/CommBank.Tests/Fake/FakeGoalsService.cs +++ b/CommBank.Tests/Fake/FakeGoalsService.cs @@ -19,7 +19,7 @@ public async Task> GetAsync() => await Task.FromResult(_goals); public async Task?> GetForUserAsync(string id) => - await Task.FromResult(_goals); + await Task.FromResult(_goals.Where(g => g.UserId == id).ToList()); public async Task GetAsync(string id) => await Task.FromResult(_goal); diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..7466d991 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -66,9 +66,26 @@ public async void Get() 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