Files
PyroFetes-Sujet1/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs
2025-10-09 17:17:42 +02:00

35 lines
975 B
C#

using API.DTO.Classification.Request;
using API.DTO.Classification.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Classification;
public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateClassificationDto, GetClassificationDto>
{
public override void Configure()
{
Post("/api/classifications");
AllowAnonymous();
}
public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct)
{
Models.Classification classification = new ()
{
Label = req.Label
};
pyrofetesdbcontext.Classifications.Add(classification);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Classification créée avec succès !");
GetClassificationDto responseDto = new ()
{
Label = req.Label
};
await Send.OkAsync(responseDto, ct);
}
}