Add services and controllers for games (#12)

Co-authored-by: Maxime Adler <madler@sqli.com>
Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
2025-04-12 21:34:45 +02:00
parent 3537465588
commit 3ea96186e7
32 changed files with 531 additions and 23 deletions

View File

@@ -1,17 +1,17 @@
using GameIdeas.Resources;
using GameIdeas.WebAPI.Context;
using GameIdeas.WebAPI.Profiles;
using GameIdeas.WebAPI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Data;
using System.Data.Common;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
#if DEBUG
Load("../../../../.env");
LoadEnvironmentVariable("../../../../.env");
#else
Load(".env");
LoadEnvironmentVariable(".env");
#endif
Action<DbContextOptionsBuilder> dbContextOptions = options =>
@@ -22,8 +22,7 @@ Action<DbContextOptionsBuilder> dbContextOptions = options =>
{
npgOption.CommandTimeout(60);
npgOption.MigrationsAssembly("GameIdeas.WebAPI");
})
.LogTo(Console.WriteLine);
});
};
// Add services to the container.
@@ -32,7 +31,14 @@ services.AddDbContext<GameIdeasContext>(dbContextOptions);
services.AddSingleton<TranslationService>();
services.AddSingleton<Translations>();
services.AddScoped<GameService>();
services.AddAutoMapper(typeof(GameProfile).Assembly);
services.AddAutoMapper(typeof(UserProfile).Assembly);
services.AddAutoMapper(typeof(CategoryProfile).Assembly);
services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
services.AddOpenApi();
@@ -40,6 +46,7 @@ services.AddCors(option => option.AddDefaultPolicy(policy =>
policy.WithOrigins("http://localhost:5172", "http://localhost:7060")
.AllowAnyHeader()
.WithMethods("GET", "POST", "PUT", "DELETE")));
var app = builder.Build();
await LoadTranslations();
@@ -85,7 +92,7 @@ string GetConnectionString()
return $"Host={host};Username={login};Password={pass};Database={database}";
}
static void Load(string filePath)
static void LoadEnvironmentVariable(string filePath)
{
if (!File.Exists(filePath))
return;