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
17 changes: 4 additions & 13 deletions CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
</ItemGroup>

<ItemGroup>
<None Remove="Newtonsoft.Json" />
<None Remove="BCrypt.Net-Next" />
<None Remove="Microsoft.Extensions.DependencyInjection" />
<None Remove="MongoDB.Driver" />
<None Remove="Services\" />
<None Remove="Models\" />
<None Remove="Properties\" />
<None Remove="Data\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
<Folder Include="Models\" />
<Folder Include="Properties\" />
<Folder Include="Data\" />
</ItemGroup>
</Project>

</Project>
3 changes: 3 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public class Goal

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

// New optional icon field
public string? Icon { get; set; }
}
64 changes: 18 additions & 46 deletions CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
using CommBank.Models;
using CommBank.Services;
using MongoDB.Driver;
using MongoDB.Driver;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

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

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoDatabase = mongoClient.GetDatabase("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);

builder.Services.AddSingleton(accountsService);
builder.Services.AddSingleton(authService);
builder.Services.AddSingleton(goalsService);
builder.Services.AddSingleton(tagsService);
builder.Services.AddSingleton(transactionsService);
builder.Services.AddSingleton(usersService);

builder.Services.AddCors();

var app = builder.Build();

app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());

if (app.Environment.IsDevelopment())
try
{
app.UseSwagger();
app.UseSwaggerUI();
}
var connectionString =
"mongodb+srv://shaikshah:Test123456@cluster0.8uzhwc1.mongodb.net/?appName=Cluster0";

app.UseHttpsRedirection();
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.ServerApi = new ServerApi(ServerApiVersion.V1);

app.UseAuthorization();
var client = new MongoClient(settings);

app.MapControllers();
var dbs = client.ListDatabaseNames().ToList();

app.Run();
Console.WriteLine("SUCCESS!");

foreach (var db in dbs)
{
Console.WriteLine(db);
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
5 changes: 3 additions & 2 deletions CommBank-Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:11366;http://localhost:5203",
"applicationUrl": "http://localhost:5203",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -27,4 +27,5 @@
}
}
}
}
}

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": "mongodb+srv://shaikshah:Test123456@cluster0.8uzhwc1.mongodb.net/?appName=Cluster0"
}
}