Initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user