From 7af9e7db84f42387d0ea33c698fa1205c66df39b Mon Sep 17 00:00:00 2001 From: Dhanush Date: Sat, 27 Jun 2026 16:34:42 +0530 Subject: [PATCH 1/5] Completed CommBank Forage project --- CommBank-Server/Models/Goal.cs | 3 +++ CommBank-Server/Secrets.json | 2 +- CommBank-Server/Services/GoalService.cs | 2 +- Server.sln | 3 +-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..92d8dd2a 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -25,6 +25,9 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public List? TagIds { get; set; } + [BsonElement("icon")] + public string? Icon { get; set; } + [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } } \ No newline at end of file diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf949..ea505877 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "CommBank": "mongodb+srv://dhanushraju24_db_user:Dhanu2012@m0.utwvbze.mongodb.net/?appName=M0" } } \ No newline at end of file diff --git a/CommBank-Server/Services/GoalService.cs b/CommBank-Server/Services/GoalService.cs index b0c600a1..fb240efa 100644 --- a/CommBank-Server/Services/GoalService.cs +++ b/CommBank-Server/Services/GoalService.cs @@ -9,7 +9,7 @@ public class GoalsService : IGoalsService public GoalsService(IMongoDatabase mongoDatabase) { - _goalsCollection = mongoDatabase.GetCollection("Goals"); + _goalsCollection = mongoDatabase.GetCollection("goals"); } public async Task> GetAsync() => diff --git a/Server.sln b/Server.sln index 326f9844..9e1ac66f 100644 --- a/Server.sln +++ b/Server.sln @@ -1,5 +1,4 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 25.0.1700.1 MinimumVisualStudioVersion = 10.0.40219.1 From bcb8f37262aedfee02c28973af6a6565567b0002 Mon Sep 17 00:00:00 2001 From: Dhanush N Date: Sat, 27 Jun 2026 17:12:03 +0530 Subject: [PATCH 2/5] Create README.md --- README.md | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..d895e19a --- /dev/null +++ b/README.md @@ -0,0 +1,259 @@ +# Commonwealth Bank Forage – Task 1 + +## Objective + +The task was to extend the Goal model by adding a new property called **Icon** and ensure that the API returns this field when goal data is requested. + +--- + +# Step 1: Understand the Existing Architecture + +The project follows a typical ASP.NET Core + MongoDB architecture: + +MongoDB Database +↓ +Services Layer +↓ +Controllers +↓ +API Endpoints +↓ +Postman / Swagger + +When a request is sent to: + +GET /api/Goal + +the flow is: + +GoalController +↓ +GoalsService +↓ +MongoDB Collection (Goals) +↓ +Return JSON Response + +--- + +# Step 2: Setup MongoDB Atlas + +### Database + +CommBank + +### Collections + +- accounts +- goals +- tags +- transactions +- users + +Imported: + +- Accounts.json +- Goals.json +- Tags.json +- Transactions.json +- Users.json + +--- + +# Step 3: Connect Backend to MongoDB + +In `Program.cs`: + +```csharp +var mongoClient = + new MongoClient( + builder.Configuration.GetConnectionString("CommBank")); + +var mongoDatabase = + mongoClient.GetDatabase("CommBank"); +``` +This creates a connection to MongoDB Atlas and accesses the CommBank database. + +--- + +# Step 4: Verify Existing API + +Using Swagger and Postman: + +```http +GET /api/Goal +``` + +Initially, goal objects did not contain an `icon` field. + +--- + +# Step 5: Extend the Goal Model + +File: + +`Models/Goal.cs` + +Added: + +```csharp +[BsonElement("icon")] +public string? Icon { get; set; } +``` + +--- + +# Why This Was Needed + +MongoDB documents contained an `icon` field, but the Goal model did not. + +Without the property: + +```csharp +public string? Icon { get; set; } +``` + +MongoDB could not map the field and threw: + +```text +Element 'icon' does not match any field or property of class CommBank.Models.Goal +``` + +Adding the property fixed the issue. + +--- + +# Step 6: Add Icon Values to MongoDB + +Examples: + +```json +{ + "Name": "House Down Payment", + "icon": "home" +} +``` + +```json +{ + "Name": "Tesla Model Y", + "icon": "car" +} +``` + +```json +{ + "Name": "Trip to London", + "icon": "flight" +} +``` + +```json +{ + "Name": "Trip to NYC", + "icon": "location" +} +``` + +--- + +# Step 7: Build and Run the Application + +```bash +dotnet build +dotnet run +``` + +The backend started successfully. + +--- + +# Step 8: Test the API Again + +Request: + +```http +GET /api/Goal +``` + +Response now includes: + +```json +{ + "name": "House Down Payment", + "balance": 73501.82, + "icon": "home" +} +``` + +This confirms the implementation works correctly. + +--- + +# Step 9: Commit and Push to GitHub + +```bash +git add . +git commit -m "Completed CommBank Forage project" +git push origin main +``` + +Changes were successfully pushed to GitHub. + +--- + +# Final Result + +### Before + +```json +{ + "name": "House Down Payment", + "balance": 73501.82 +} +``` + +### After + +```json +{ + "name": "House Down Payment", + "balance": 73501.82, + "icon": "home" +} +``` + +--- + +# Skills Demonstrated + +### MongoDB +- Atlas setup +- Database creation +- Collection creation +- JSON import +- Document updates + +### ASP.NET Core +- Models +- Services +- Controllers +- Dependency Injection +- REST APIs + +### API Testing +- Swagger +- Postman +- GET requests +- JSON responses + +### Git & GitHub +- Commits +- Push operations +- Repository management + +--- + +# Summary + +Successfully extended the Goal model by adding an optional Icon property, updated MongoDB documents with icon values, and verified through Swagger and Postman that the API correctly returns the new icon field in goal responses. From be8b9075622a0d8c0f705cc23a6abc67aef86f87 Mon Sep 17 00:00:00 2001 From: Dhanush Date: Sun, 28 Jun 2026 14:21:55 +0530 Subject: [PATCH 3/5] Completed Task 4 - Added GetForUser test coverage --- CommBank.Tests/GoalControllerTests.cs | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..6565984f 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -62,13 +62,32 @@ public async void Get() Assert.NotEqual(goals[1], result.Value); } - [Fact] - public async void GetForUser() + + +[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(users[0].Id!); + + // Assert + Assert.NotNull(result); + + foreach (Goal goal in result!) { - // Arrange - - // Act - - // Assert + Assert.IsAssignableFrom(goal); } +} } \ No newline at end of file From 837e0fa00c55a116e40456ffd8323b1707e79b52 Mon Sep 17 00:00:00 2001 From: Dhanush Date: Sun, 28 Jun 2026 14:33:44 +0530 Subject: [PATCH 4/5] Complete Task 5 - Create Pull Request --- CommBank-Server/package-lock.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 CommBank-Server/package-lock.json diff --git a/CommBank-Server/package-lock.json b/CommBank-Server/package-lock.json new file mode 100644 index 00000000..84d087c6 --- /dev/null +++ b/CommBank-Server/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "CommBank-Server", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} From 9b3810f638bf8fc03e28af18845d65774bf5cfe2 Mon Sep 17 00:00:00 2001 From: Dhanush N Date: Sun, 28 Jun 2026 15:15:40 +0530 Subject: [PATCH 5/5] Create pull-request.md --- pull-request.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pull-request.md diff --git a/pull-request.md b/pull-request.md new file mode 100644 index 00000000..6aec343b --- /dev/null +++ b/pull-request.md @@ -0,0 +1,20 @@ +# Task 5 - Create Pull Request + +## Pull Request Information + +Title: Complete Task 5 - Create Pull Request + +Pull Request Number: #263 + +Branch: task-5-pull-request + +## Changes Made + +- Created a new branch named task-5-pull-request. +- Added and committed project changes. +- Pushed the branch to GitHub. +- Created Pull Request #263. + +## Purpose + +This Pull Request demonstrates the use of Git branching, committing, pushing changes, and creating Pull Requests.