diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj
index 983cc88..0282caf 100644
--- a/CommBank-Server/CommBank.csproj
+++ b/CommBank-Server/CommBank.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs
index 77ff1ad..b38f057 100644
--- a/CommBank-Server/Models/Goal.cs
+++ b/CommBank-Server/Models/Goal.cs
@@ -27,4 +27,5 @@ 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/Program.cs b/CommBank-Server/Program.cs
index a88e560..92b5a8e 100644
--- a/CommBank-Server/Program.cs
+++ b/CommBank-Server/Program.cs
@@ -4,38 +4,41 @@
var builder = WebApplication.CreateBuilder(args);
+// Add services
builder.Services.AddControllers();
-
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
-builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");
+// ✅ Load appsettings.json (IMPORTANT FIX)
+builder.Configuration
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
-var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
-var mongoDatabase = mongoClient.GetDatabase("CommBank");
+// ✅ Get connection string properly
+var connectionString = builder.Configuration.GetConnectionString("CommBank");
-IAccountsService accountsService = new AccountsService(mongoDatabase);
-IAuthService authService = new AuthService(mongoDatabase);
-IGoalsService goalsService = new GoalsService(mongoDatabase);
-ITagsService tagsService = new TagsService(mongoDatabase);
-ITransactionsService transactionsService = new TransactionsService(mongoDatabase);
-IUsersService usersService = new UsersService(mongoDatabase);
+// ✅ Create MongoDB client
+var mongoClient = new MongoClient(connectionString);
+var mongoDatabase = mongoClient.GetDatabase("CommBank");
-builder.Services.AddSingleton(accountsService);
-builder.Services.AddSingleton(authService);
-builder.Services.AddSingleton(goalsService);
-builder.Services.AddSingleton(tagsService);
-builder.Services.AddSingleton(transactionsService);
-builder.Services.AddSingleton(usersService);
+// Register services
+builder.Services.AddSingleton(new AccountsService(mongoDatabase));
+builder.Services.AddSingleton(new AuthService(mongoDatabase));
+builder.Services.AddSingleton(new GoalsService(mongoDatabase));
+builder.Services.AddSingleton(new TagsService(mongoDatabase));
+builder.Services.AddSingleton(new TransactionsService(mongoDatabase));
+builder.Services.AddSingleton(new UsersService(mongoDatabase));
+// Enable CORS
builder.Services.AddCors();
var app = builder.Build();
-app.UseCors(builder => builder
- .AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader());
+// Configure middleware
+app.UseCors(policy =>
+ policy.AllowAnyOrigin()
+ .AllowAnyMethod()
+ .AllowAnyHeader());
if (app.Environment.IsDevelopment())
{
@@ -44,10 +47,8 @@
}
app.UseHttpsRedirection();
-
app.UseAuthorization();
app.MapControllers();
-app.Run();
-
+app.Run();
\ No newline at end of file
diff --git a/CommBank-Server/appsettings.json b/CommBank-Server/appsettings.json
index af0538f..340052f 100644
--- a/CommBank-Server/appsettings.json
+++ b/CommBank-Server/appsettings.json
@@ -1,4 +1,7 @@
{
+ "ConnectionStrings": {
+ "CommBank": "mongodb+srv://joshna:joshna2006@cluster0.mqiyhab.mongodb.net/?retryWrites=true&w=majority"
+ },
"Logging": {
"LogLevel": {
"Default": "Information",
@@ -6,5 +9,4 @@
}
},
"AllowedHosts": "*"
-}
-
+}
\ No newline at end of file
diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs
index 8380181..875e247 100644
--- a/CommBank.Tests/GoalControllerTests.cs
+++ b/CommBank.Tests/GoalControllerTests.cs
@@ -1,4 +1,6 @@
-using CommBank.Controllers;
+using System.Collections.Generic;
+using Xunit;
+using CommBank.Controllers;
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
@@ -66,9 +68,28 @@ 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);
+
+ var userId = users[0].Id;
+
// Act
-
+ var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
+ controller.ControllerContext.HttpContext = httpContext;
+
+ var actionResult = await controller.Get(userId!);
+ var okResult = Assert.IsType(actionResult.Result);
+ var result = Assert.IsAssignableFrom>(okResult.Value);
+
// Assert
+ foreach (var goal in result)
+ {
+ Assert.Equal(userId, goal.UserId);
+ }
}
}
\ No newline at end of file