forked from sanchezvem/PyroFetes
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using API.DTO.Classification.Request;
|
|
using API.DTO.Classification.Response;
|
|
using FastEndpoints;
|
|
|
|
namespace PyroFetes.Endpoints.Classification;
|
|
|
|
public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateClassificationDto, GetClassificationDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Put("/api/classifications"); //Met à jour la classification en fonction de l'id
|
|
AllowAnonymous(); //Autorise l'accès sans authentification
|
|
}
|
|
|
|
public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct)
|
|
{
|
|
|
|
Models.Classification classification = new() //Met à jour la classification
|
|
{
|
|
Label = req.Label
|
|
};
|
|
pyrofetesdbcontext.Add(classification); //ajoute la classification dans la bdd
|
|
await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements
|
|
|
|
GetClassificationDto response = new() //renvoie l'id et le nom
|
|
{
|
|
Id = req.Id,
|
|
Label = req.Label
|
|
};
|
|
|
|
await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client
|
|
|
|
}
|
|
} |