forked from sanchezvem/PyroFetes
35 lines
987 B
C#
35 lines
987 B
C#
using PyroFetes.DTO.Classification.Request;
|
|
using PyroFetes.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);
|
|
}
|
|
} |