Files
2026-05-05 10:39:43 +02:00

61 lines
1.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FastEndpoints;
using FastEndpoints.Swagger;
using MetaCourse.Api.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
var builder = WebApplication.CreateBuilder(args);
// Database
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer("Server=romaric-thibault.fr;Database=arsene_MetaCourseV2;User Id=arsene;Password=Onto9-Cage-Afflicted;TrustServerCertificate=true;")
.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning)));
// AutoMapper
builder.Services.AddAutoMapper(typeof(Program).Assembly);
// FastEndpoints + Swagger
builder.Services.AddFastEndpoints()
.SwaggerDocument(o =>
{
o.DocumentSettings = s =>
{
s.Title = "MetaCourse API";
s.Version = "v1";
s.Description = "API REST pour la plateforme MetaCourse gestion de cours, sujets, ressources et progression.";
};
});
// CORS (pour les clients front-end)
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
});
var app = builder.Build();
app.UseCors("AllowAll");
app.UseFastEndpoints(c =>
{
c.Errors.ResponseBuilder = (failures, ctx, statusCode) =>
{
return new
{
StatusCode = statusCode,
Errors = failures.Select(f => new { f.PropertyName, f.ErrorMessage })
};
};
});
app.UseSwaggerGen();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
db.Database.EnsureCreated();
}
app.Run();