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: 2 additions & 2 deletions CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
<AssemblyName>CommBank-Server</AssemblyName>
<UserSecretsId>273e48ab-d4aa-4a94-9ef6-a9e18a643262</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="MongoDB.Driver" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -30,6 +31,5 @@
<Folder Include="Services\" />
<Folder Include="Models\" />
<Folder Include="Properties\" />
<Folder Include="Data\" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ public async Task<IActionResult> 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);

Expand Down
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }

public string? Icon {get; set; }
}
2 changes: 1 addition & 1 deletion 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://richhamwi:[email protected]/?retryWrites=true&w=majority&appName=Cluster0"
}
}
23 changes: 20 additions & 3 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
index++;
}

}
}
10 changes: 8 additions & 2 deletions Server.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down