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
2 changes: 1 addition & 1 deletion CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<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.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

namespace CommBank.Controllers;


/*
[Route("api/[controller]")]

This app is an API and the current controller (in this case it is GoalController)
is mapped under [Route("api/[controller]")]

So the endpoint is http://localhost:5203/api/Goal

On this url, it shows this:
[{"id":"62a3f587102e921da1253d32","name":"House Down Payment","targetAmount":100000,"targetDate":"2025-01-08T05:00:00Z","balance":73501.82,"created":"2022-06-11T01:53:10.857Z","transactionIds":null,"tagIds":null,"userId":"62a29c15f4605c4c9fa7f306"},{"id":"62a3f5e0102e921da1253d33","name":"Tesla Model Y","targetAmount":60000,"targetDate":"2022-09-01T04:00:00Z","balance":43840.02,"created":"2022-06-11T01:54:40.95Z","transactionIds":null,"tagIds":null,"userId":"62a29c15f4605c4c9fa7f306"},{"id":"62a3f62e102e921da1253d34","name":"Trip to London","targetAmount":3500,"targetDate":"2022-08-02T04:00:00Z","balance":753.89,"created":"2022-06-11T01:55:58.236Z","transactionIds":null,"tagIds":null,"userId":"62a29c15f4605c4c9fa7f306"},{"id":"62a61945fa15f1cd18516a5f","name":"Trip to NYC","targetAmount":800,"targetDate":"2023-12-10T05:00:00Z","balance":0,"created":"2022-06-12T16:57:45.668Z",
"transactionIds":null,"tagIds":null,"userId":"62a29c15f4605c4c9fa7f306"}]

*/
[ApiController]
[Route("api/[controller]")]
public class GoalController : ControllerBase
Expand Down
12 changes: 10 additions & 2 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

namespace CommBank.Models;

/*
This is a data model (also called a POCO – Plain Old CLR Object) representing a
financial goal in the CommBank system.

*/

public class Goal
{
[BsonId]
[BsonId] //marks the property Id as the primary key
[BsonRepresentation(BsonType.ObjectId)]
public string? Id { get; set; }
public string? Id { get; set; } //Tells the MongoDB driver to treat this string as an ObjectId in the database.

public string? Name { get; set; }

Expand All @@ -25,6 +31,8 @@ public class Goal
[BsonRepresentation(BsonType.ObjectId)]
public List<string>? TagIds { get; set; }

public string? Icon { get; set; } //add an optional public icon of field string type

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }
}
7 changes: 7 additions & 0 deletions CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");

//Retrieves the database "CommBank"
//Retrieves the mongo client "CommBank"

/*
Mongo collection names:
Accounts, Tags, Goals, Users, Transactions
*/
var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoDatabase = mongoClient.GetDatabase("CommBank");

Expand Down
4 changes: 2 additions & 2 deletions 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://Stuvan:<pass>@stevencommbankcluster.ly2wxzc.mongodb.net/?retryWrites=true&w=majority&appName=StevenCommBankCluster"
}
}
}
35 changes: 32 additions & 3 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async void GetAll()
}
}

// a test that should run with no input (from xUnit).
[Fact]
public async void Get()
{
Expand All @@ -62,13 +63,41 @@ public async void Get()
Assert.NotEqual(goals[1], result.Value);
}

[Fact]
[Fact] // a test that should run with no input (from xUnit).
public async void GetForUser()
{
// Arrange
/*
Arrange: Here, we set up the tests
-get fake goals and users
-Creates fake services (FakeGoalsService, FakeUsersService) which
implement interfaces the controller expects.
-Instantiates the GoalController with those fake services
*/
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
/*
Act
-Manually set up an HTTP context for the controller
(so it's not null when running outside of a real request).
-Calls the method GetForUser with the UserId of the first goal.
*/
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++;
}
}
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions task1/Accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[{
"_id": {
"$oid": "62a3e6aad25715026d1a2938"
},
"Number": 123456789,
"Name": "Tag's Goal Saver",
"Balance": 6483.81,
"AccountType": "GoalSaver",
"TransactionIds": [
{
"$oid": "62a3a284d07648900df72860"
},
{
"$oid": "62a3a2ded07648900df72861"
},
{
"$oid": "62a3a2ded07648900df72862"
},
{
"$oid": "62a3a2ded07648900df72863"
},
{
"$oid": "62a3a2ded07648900df72864"
},
{
"$oid": "62a3a2ded07648900df72865"
},
{
"$oid": "62a3a2ded07648900df72866"
},
{
"$oid": "62a3a2ded07648900df72867"
},
{
"$oid": "62a3a2ded07648900df72868"
},
{
"$oid": "62a3a2ded07648900df72869"
},
{
"$oid": "62a3a344d07648900df7286a"
},
{
"$oid": "62a3a344d07648900df7286b"
},
{
"$oid": "62a3a344d07648900df7286c"
},
{
"$oid": "62a3a344d07648900df7286d"
}
]
}]
94 changes: 94 additions & 0 deletions task1/Goals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
[
{
"_id": {
"$oid": "62a3f587102e921da1253d32"
},
"Name": "House Down Payment",
"TargetAmount": 100000,
"TargetDate": {
"$date": {
"$numberLong": "1736312400000"
}
},
"Balance": 73501.82,
"Created": {
"$date": {
"$numberLong": "1654912390857"
}
},
"TransactionIds": null,
"TagIds": null,
"UserId": {
"$oid": "62a29c15f4605c4c9fa7f306"
}
},
{
"_id": {
"$oid": "62a3f5e0102e921da1253d33"
},
"Name": "Tesla Model Y",
"TargetAmount": 60000,
"TargetDate": {
"$date": {
"$numberLong": "1662004800000"
}
},
"Balance": 43840.02,
"Created": {
"$date": {
"$numberLong": "1654912480950"
}
},
"TransactionIds": null,
"TagIds": null,
"UserId": {
"$oid": "62a29c15f4605c4c9fa7f306"
}
},
{
"_id": {
"$oid": "62a3f62e102e921da1253d34"
},
"Name": "Trip to London",
"TargetAmount": 3500,
"TargetDate": {
"$date": {
"$numberLong": "1659412800000"
}
},
"Created": {
"$date": {
"$numberLong": "1654912558236"
}
},
"TransactionIds": null,
"TagIds": null,
"Balance": 753.89,
"UserId": {
"$oid": "62a29c15f4605c4c9fa7f306"
}
},
{
"_id": {
"$oid": "62a61945fa15f1cd18516a5f"
},
"Name": "Trip to NYC",
"TargetAmount": 800,
"TargetDate": {
"$date": {
"$numberLong": "1702184400000"
}
},
"Balance": 0,
"Created": {
"$date": {
"$numberLong": "1655053065668"
}
},
"TransactionIds": null,
"TagIds": null,
"UserId": {
"$oid": "62a29c15f4605c4c9fa7f306"
}
}
]
26 changes: 26 additions & 0 deletions task1/Tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[{
"_id": {
"$oid": "62a39d27025ca1ba8f1f1c1e"
},
"Name": "Groceries"
},{
"_id": {
"$oid": "62a39d42025ca1ba8f1f1c1f"
},
"Name": "Restaurant"
},{
"_id": {
"$oid": "62a39d4e025ca1ba8f1f1c20"
},
"Name": "Income"
},{
"_id": {
"$oid": "62a39d5a025ca1ba8f1f1c21"
},
"Name": "Gas"
},{
"_id": {
"$oid": "62a39d63025ca1ba8f1f1c22"
},
"Name": "Investment"
}]
Loading