diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj index 983cc88..3e5aaa8 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server/CommBank.csproj @@ -1,7 +1,7 @@ - net6.0 + net10.0 enable enable CommBank_Server diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..d21b2d9 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -1,30 +1,23 @@ -using MongoDB.Bson; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; - namespace CommBank.Models; - public class Goal { [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string? Id { get; set; } - public string? Name { get; set; } - public UInt64 TargetAmount { get; set; } = 0; - public DateTime TargetDate { get; set; } - public double Balance { get; set; } = 0.00; - public DateTime Created { get; set; } = DateTime.Now; - [BsonRepresentation(BsonType.ObjectId)] public List? TransactionIds { get; set; } - [BsonRepresentation(BsonType.ObjectId)] public List? TagIds { get; set; } - [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } -} \ No newline at end of file + [BsonIgnoreIfNull] + [BsonElement("icon")] + public string? Icon { get; set; } +} diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs index a88e560..7e65765 100644 --- a/CommBank-Server/Program.cs +++ b/CommBank-Server/Program.cs @@ -11,8 +11,8 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json"); -var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank")); -var mongoDatabase = mongoClient.GetDatabase("CommBank"); +var mongoClient = new MongoClient("mongodb+srv://user1:pass1234@commbank-cluster.azmyy27.mongodb.net/?appName=commbank-cluster"); +var mongoDatabase = mongoClient.GetDatabase("CommBankDb"); IAccountsService accountsService = new AccountsService(mongoDatabase); IAuthService authService = new AuthService(mongoDatabase); diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf94..b91e850 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "CommBank": "mongodb+srv://commbankuser:CommBank123@commbank-cluster.azmyy27.mongodb.net/?appName=commbank-cluster" } } \ No newline at end of file diff --git a/CommBank-Server/appsettings.json b/CommBank-Server/appsettings.json index af0538f..8978acd 100644 --- a/CommBank-Server/appsettings.json +++ b/CommBank-Server/appsettings.json @@ -5,6 +5,10 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} - + "AllowedHosts": "*", + "CommBankDatabaseSettings": { + "ConnectionString": "mongodb+srv://commbankuser:CommBank123@commbank-cluster.azmyy27.mongodb.net/?appName=commbank-cluster", + "DatabaseName": "CommBankDb", + "GoalsCollectionName": "Goals" + } +} \ No newline at end of file diff --git a/CommBank.Tests/CommBank.Tests.csproj b/CommBank.Tests/CommBank.Tests.csproj index 4d9413f..3ca5f27 100644 --- a/CommBank.Tests/CommBank.Tests.csproj +++ b/CommBank.Tests/CommBank.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net10.0 enable enable diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..2c06ade 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -1,4 +1,4 @@ -using CommBank.Controllers; +using CommBank.Controllers; using CommBank.Services; using CommBank.Models; using CommBank.Tests.Fake; @@ -35,8 +35,8 @@ public async void GetAll() foreach (Goal goal in result) { Assert.IsAssignableFrom(goal); - Assert.Equal(goals[index].Id, goal.Id); - Assert.Equal(goals[index].Name, goal.Name); + Assert.Equal(goals[0].UserId, goal.UserId); + index++; } } @@ -66,9 +66,26 @@ 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); + // 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); + Assert.Equal(goals[0].UserId, goal.UserId); + + index++; + } } -} \ No newline at end of file +}