using API.DTO.Effect.Request; using API.DTO.Effect.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Effect; public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { public override void Configure() { Put("Api/effects/{@id}", x => new { x.Id }); AllowAnonymous(); } public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct) { Models.Effect? effectToEdit = await pyrofetesdbcontext .Effects .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); if (effectToEdit == null) { Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé."); await Send.NotFoundAsync(ct); return; } effectToEdit.Label = req.Label; await pyrofetesdbcontext.SaveChangesAsync(ct); GetEffectDto responseDto = new() { Id = req.Id, Label = req.Label, }; await Send.OkAsync(responseDto, ct); } }