diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj
index 983cc88..869ee0d 100644
--- a/CommBank-Server/CommBank.csproj
+++ b/CommBank-Server/CommBank.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/CommBank-Server/Controllers/GoalController.cs b/CommBank-Server/Controllers/GoalController.cs
index 98271a5..c5d15af 100644
--- a/CommBank-Server/Controllers/GoalController.cs
+++ b/CommBank-Server/Controllers/GoalController.cs
@@ -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
diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs
index 77ff1ad..be136a7 100644
--- a/CommBank-Server/Models/Goal.cs
+++ b/CommBank-Server/Models/Goal.cs
@@ -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; }
@@ -25,6 +31,8 @@ public class Goal
[BsonRepresentation(BsonType.ObjectId)]
public List? 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; }
}
\ No newline at end of file
diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs
index a88e560..9eeb4e4 100644
--- a/CommBank-Server/Program.cs
+++ b/CommBank-Server/Program.cs
@@ -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");
diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json
index 0e5bf94..ff28592 100644
--- a/CommBank-Server/Secrets.json
+++ b/CommBank-Server/Secrets.json
@@ -1,5 +1,5 @@
{
"ConnectionStrings": {
- "CommBank": "{CONNECTION_STRING}"
+ "CommBank": "mongodb+srv://Stuvan:@stevencommbankcluster.ly2wxzc.mongodb.net/?retryWrites=true&w=majority&appName=StevenCommBankCluster"
}
-}
\ No newline at end of file
+}
diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs
index 8380181..22d8986 100644
--- a/CommBank.Tests/GoalControllerTests.cs
+++ b/CommBank.Tests/GoalControllerTests.cs
@@ -41,6 +41,7 @@ public async void GetAll()
}
}
+ // a test that should run with no input (from xUnit).
[Fact]
public async void Get()
{
@@ -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);
+ Assert.Equal(goals[0].UserId, goal.UserId);
+ index++;
+ }
}
}
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..84d087c
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,6 @@
+{
+ "name": "CommBank-Server",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {}
+}
diff --git a/task1/Accounts.json b/task1/Accounts.json
new file mode 100644
index 0000000..c94a91d
--- /dev/null
+++ b/task1/Accounts.json
@@ -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"
+ }
+ ]
+}]
\ No newline at end of file
diff --git a/task1/Goals.json b/task1/Goals.json
new file mode 100644
index 0000000..f42d18b
--- /dev/null
+++ b/task1/Goals.json
@@ -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"
+ }
+ }
+]
\ No newline at end of file
diff --git a/task1/Tags.json b/task1/Tags.json
new file mode 100644
index 0000000..202e1ab
--- /dev/null
+++ b/task1/Tags.json
@@ -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"
+}]
\ No newline at end of file
diff --git a/task1/Transactions.json b/task1/Transactions.json
new file mode 100644
index 0000000..9320984
--- /dev/null
+++ b/task1/Transactions.json
@@ -0,0 +1,310 @@
+[
+ {
+ "_id": {
+ "$oid": "62a3a284d07648900df72860"
+ },
+ "TransactionType": "Debit",
+ "Amount": 135.39,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891140391"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d27025ca1ba8f1f1c1e"
+ }
+ ],
+ "Description": "Whole Foods",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a2ded07648900df72861"
+ },
+ "TransactionType": "Debit",
+ "Amount": 139.26,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d27025ca1ba8f1f1c1e"
+ }
+ ],
+ "Description": "Whole Foods",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a2ebd07648900df72862"
+ },
+ "TransactionType": "Debit",
+ "Amount": 26.39,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891243091"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d42025ca1ba8f1f1c1f"
+ }
+ ],
+ "Description": "Chipotle",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a2ecd07648900df72863"
+ },
+ "TransactionType": "Debit",
+ "Amount": 21.9,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d42025ca1ba8f1f1c1f"
+ }
+ ],
+ "Description": "Chipotle",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a316d07648900df72864"
+ },
+ "TransactionType": "Credit",
+ "Amount": 5622.81,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891286080"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d4e025ca1ba8f1f1c20"
+ }
+ ],
+ "Description": "Dropbox",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a318d07648900df72865"
+ },
+ "TransactionType": "Credit",
+ "Amount": 5622.92,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d4e025ca1ba8f1f1c20"
+ }
+ ],
+ "Description": "Dropbox",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a323d07648900df72866"
+ },
+ "TransactionType": "Credit",
+ "Amount": 1439.18,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891299481"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d4e025ca1ba8f1f1c20"
+ }
+ ],
+ "Description": "Fencer",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a324d07648900df72867"
+ },
+ "TransactionType": "Credit",
+ "Amount": 1439.89,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d4e025ca1ba8f1f1c20"
+ }
+ ],
+ "Description": "Fencer",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a337d07648900df72868"
+ },
+ "TransactionType": "Debit",
+ "Amount": 44.52,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891319411"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d5a025ca1ba8f1f1c21"
+ }
+ ],
+ "Description": "Gas",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a338d07648900df72869"
+ },
+ "TransactionType": "Debit",
+ "Amount": 44.13,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d5a025ca1ba8f1f1c21"
+ }
+ ],
+ "Description": "Gas",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a344d07648900df7286a"
+ },
+ "TransactionType": "Debit",
+ "Amount": 1500,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891332111"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d63025ca1ba8f1f1c22"
+ }
+ ],
+ "Description": "Coinbase",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a344d07648900df7286b"
+ },
+ "TransactionType": "Debit",
+ "Amount": 1500,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d63025ca1ba8f1f1c22"
+ }
+ ],
+ "Description": "Coinbase",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a348d07648900df7286c"
+ },
+ "TransactionType": "Debit",
+ "Amount": 1500,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654891336929"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d63025ca1ba8f1f1c22"
+ }
+ ],
+ "Description": "Titan",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ },
+ {
+ "_id": {
+ "$oid": "62a3a349d07648900df7286d"
+ },
+ "TransactionType": "Debit",
+ "Amount": 1500,
+ "DateTime": {
+ "$date": {
+ "$numberLong": "1654027230566"
+ }
+ },
+ "GoalId": null,
+ "TagIds": [
+ {
+ "$oid": "62a39d63025ca1ba8f1f1c22"
+ }
+ ],
+ "Description": "Titan",
+ "UserId": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ }
+ }
+]
\ No newline at end of file
diff --git a/task1/Users.json b/task1/Users.json
new file mode 100644
index 0000000..aa8243c
--- /dev/null
+++ b/task1/Users.json
@@ -0,0 +1,69 @@
+[
+ {
+ "_id": {
+ "$oid": "62a29c15f4605c4c9fa7f306"
+ },
+ "Name": "Tag Ramotar",
+ "Email": "tag@dropbox.com",
+ "Password": "$2a$11$10VhY5XIwBeWA4uLIE.sr.c34UvwLRQPD8yy7z/4iiN6ez5z2Pg1S",
+ "AccountIds": null,
+ "GoalIds": [
+ {
+ "$oid": "62a3f587102e921da1253d32"
+ },
+ {
+ "$oid": "62a3f5e0102e921da1253d33"
+ },
+ {
+ "$oid": "62a3f62e102e921da1253d34"
+ },
+ {
+ "$oid": "62a61945fa15f1cd18516a5f"
+ }
+ ],
+ "TransactionIds": [
+ {
+ "$oid": "62a3a284d07648900df72860"
+ },
+ {
+ "$oid": "62a3a2ded07648900df72861"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72862"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72863"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72864"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72865"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72866"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72867"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72868"
+ },
+ {
+ "$oid": "62a3a2ebd07648900df72869"
+ },
+ {
+ "$oid": "62a3a344d07648900df7286a"
+ },
+ {
+ "$oid": "62a3a344d07648900df7286b"
+ },
+ {
+ "$oid": "62a3a348d07648900df7286c"
+ },
+ {
+ "$oid": "62a3a349d07648900df7286d"
+ }
+ ]
+ }
+]
\ No newline at end of file
diff --git a/task1/task1Response.cs b/task1/task1Response.cs
new file mode 100644
index 0000000..b656e04
--- /dev/null
+++ b/task1/task1Response.cs
@@ -0,0 +1 @@
+{"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,"icon":"\uD83E\uDD3A","userId":"62a29c15f4605c4c9fa7f306"}
\ No newline at end of file
diff --git a/task1/task1Response.json b/task1/task1Response.json
new file mode 100644
index 0000000..b656e04
--- /dev/null
+++ b/task1/task1Response.json
@@ -0,0 +1 @@
+{"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,"icon":"\uD83E\uDD3A","userId":"62a29c15f4605c4c9fa7f306"}
\ No newline at end of file