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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,13 @@ ASALocalRun/
# Local History for Visual Studio
.localhistory/


# Environment files
.env
*.env.*
.env.local

# App configuration secrets
appsettings.Development.json
appsettings.Staging.json
appsettings.Production.json
Secrets.json
4 changes: 3 additions & 1 deletion CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
<AssemblyName>CommBank-Server</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
Expand Down
3 changes: 3 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Goal

public string? Name { get; set; }

public string? Icon { get; set; } // Icon added

public UInt64 TargetAmount { get; set; } = 0;

public DateTime TargetDate { get; set; }
Expand All @@ -27,4 +29,5 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }

}
32 changes: 23 additions & 9 deletions CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
using CommBank.Models;
using CommBank.Services;
using MongoDB.Driver;
using DotNetEnv;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
// Load .env file ONCE
Env.Load();

// Add environment variables to configuration
builder.Configuration.AddEnvironmentVariables();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");
// Optional: Keep Secrets.json for fallback
builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("Secrets.json", optional: true);

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoDatabase = mongoClient.GetDatabase("CommBank");
// Get connection string (priority: env var -> Secrets.json -> appsettings.json)
var connectionString = Environment.GetEnvironmentVariable("MONGODB_URI")
?? builder.Configuration.GetConnectionString("CommBank");

if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("MongoDB connection string is not configured. Set MONGODB_URI environment variable.");
}

var mongoClient = new MongoClient(connectionString);
var mongoDatabase = mongoClient.GetDatabase("commbank"); // FIXED: Use actual database name

// Register services
IAccountsService accountsService = new AccountsService(mongoDatabase);
IAuthService authService = new AuthService(mongoDatabase);
IGoalsService goalsService = new GoalsService(mongoDatabase);
Expand Down Expand Up @@ -44,10 +62,6 @@
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

app.Run();
2 changes: 1 addition & 1 deletion CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ConnectionStrings": {
"CommBank": "{CONNECTION_STRING}"
"Commbank": []
}
}