Skip to content
Merged
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
Empty file added Docs/Mobile/.gitkeep
Empty file.
Empty file added Docs/Server/.gitkeep
Empty file.
Empty file added Docs/Web/.gitkeep
Empty file.
Empty file added Mobile/.gitkeep
Empty file.
Empty file added Server/Attributes/.gitkeep
Empty file.
35 changes: 35 additions & 0 deletions Server/Contexts/MongoDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using MongoDB.Bson;
using MongoDB.Driver;

namespace Server.Contexts;

public static class MongoDBContext
{
public static MongoClient Client { get; set; }
private static object _lock = new object();

static MongoDBContext()
{
if (Client != null)
return;

lock (_lock)
{
if (Client != null)
return;

Client = new MongoClient(Settings.MongoConnectionString);
Console.WriteLine("Settings.MongoConnectionString: " + Settings.MongoConnectionString);

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging the MongoDB connection string to console may expose sensitive credentials in logs. Consider removing this debug output or use proper logging with appropriate log levels that can be filtered in production.

Suggested change
Console.WriteLine("Settings.MongoConnectionString: " + Settings.MongoConnectionString);
// Removed logging of MongoDB connection string to avoid exposing sensitive credentials.

Copilot uses AI. Check for mistakes.
}
}

public static IMongoDatabase GetDatabase(string databaseName)
{
return Client.GetDatabase(databaseName);
}

public static IMongoCollection<TModel> GetCollection<TModel>(string databaseName, string collectionName)
{
return GetDatabase(databaseName).GetCollection<TModel>(collectionName);
}
}
12 changes: 12 additions & 0 deletions Server/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;

namespace Server.Controllers;

public class BaseController : ControllerBase
{
public BaseController()
{
}

protected ActionResult<T> Forbid<T>(T data) => StatusCode(StatusCodes.Status403Forbidden, data);
}
Empty file added Server/Enums/.gitkeep
Empty file.
Empty file added Server/Models/Actions/.gitkeep
Empty file.
Empty file.
Empty file added Server/MongoServices/.gitkeep
Empty file.
93 changes: 93 additions & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.Text.Json;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
});

// Add HttpClient
builder.Services.AddHttpClient();

// Configure JWT Authentication
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
var jwtKey = builder.Configuration["Jwt:Key"] ?? throw new Exception("JWT key not found");
var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? throw new Exception("JWT issuer not found");
var jwtAudience = builder.Configuration["Jwt:Audience"] ?? throw new Exception("JWT audience not found");

options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtKey)),
ValidateIssuer = true,
ValidateAudience = true,
ValidIssuer = jwtIssuer,
ValidAudience = jwtAudience,
ClockSkew = TimeSpan.Zero
};
});

// Configure settings
Settings.MongoConnectionString = builder.Configuration.GetConnectionString("MongoDB") ?? throw new Exception("MongoDB connection string not found");
Settings.JwtSettings = new JwtSettings
{
Key = builder.Configuration["Jwt:Key"] ?? throw new Exception("JWT key not found"),
Issuer = builder.Configuration["Jwt:Issuer"] ?? throw new Exception("JWT issuer not found"),
Audience = builder.Configuration["Jwt:Audience"] ?? throw new Exception("JWT audience not found"),
ExpiryInDays = int.Parse(builder.Configuration["Jwt:ExpiryInDays"] ?? "7")
};
// Add this line to listen on all interfaces
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5000);
});
Comment on lines +48 to +52

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded port 5000 conflicts with the configured ports in launchSettings.json (5280 for HTTP, 7015 for HTTPS). This could cause confusion during development. Consider using configuration values or removing this if the launch settings are sufficient.

Suggested change
// Add this line to listen on all interfaces
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5000);
});

Copilot uses AI. Check for mistakes.

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler(new ExceptionHandlerOptions
{
AllowStatusCode404Response = true,
ExceptionHandlingPath = new PathString("/api/error")
});
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.Run();


return;
Comment thread
FukuInTheCode marked this conversation as resolved.
Resolved

public static class Settings
{
public static string MongoConnectionString { get; set; } = "";
public static JwtSettings JwtSettings { get; set; } = new();
}

public class JwtSettings
{
public string Key { get; set; } = "";
public string Issuer { get; set; } = "";
public string Audience { get; set; } = "";
public int ExpiryInDays { get; set; } = 7;
}
23 changes: 23 additions & 0 deletions Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5280",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7015;http://localhost:5280",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Empty file added Server/Requests/.gitkeep
Empty file.
Empty file added Server/Responses/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions Server/Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier> <!-- This line is the temp fix for the issue with the runtime identifier -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
<PackageReference Include="MongoDB.Bson" Version="2.23.1" />
Comment thread
FukuInTheCode marked this conversation as resolved.
Resolved
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
</ItemGroup>


</Project>
Empty file added Server/Services/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions Server/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Empty file added Tests/Mobile/.gitkeep
Empty file.
Empty file added Tests/Server/.gitkeep
Empty file.
Empty file added Tests/Web/.gitkeep
Empty file.
Empty file added Web/.gitkeep
Empty file.