diff --git a/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint new file mode 100644 index 0000000..2728b81 --- /dev/null +++ b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint @@ -0,0 +1,42 @@ +using API.DTO.Effect.Request; +using API.DTO.Effect.Response; +using FastEndpoints; +using Microsoft.AspNetCore.Server.Kestrel; +using Microsoft.EntityFrameworkCore; + +namespace API.Endpoints.Effect; + +public class UpdateEffectEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Put("/effect/{@id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct) + { + Models.Effect? effectToEdit = await appDbContext + .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 appDbContext.SaveChangesAsync(ct); + + GetEffectDto responseDto = new() + { + Id = req.Id, + Label = req.Label, + }; + await Send.OkAsync(responseDto, ct); + + } + +} \ No newline at end of file