From 149cd9eb3399aa2b8d4971b7f5dfa1f45e7e0e3b Mon Sep 17 00:00:00 2001 From: kieva Date: Wed, 8 Oct 2025 16:40:22 +0200 Subject: [PATCH] Ajouter PyroFetes/Endpoints/Effect/GetEffectEndpoint --- PyroFetes/Endpoints/Effect/GetEffectEndpoint | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 PyroFetes/Endpoints/Effect/GetEffectEndpoint diff --git a/PyroFetes/Endpoints/Effect/GetEffectEndpoint b/PyroFetes/Endpoints/Effect/GetEffectEndpoint new file mode 100644 index 0000000..c6230f1 --- /dev/null +++ b/PyroFetes/Endpoints/Effect/GetEffectEndpoint @@ -0,0 +1,42 @@ +using API.DTO.Effect.Response; +using FastEndpoints; +using Microsoft.AspNetCore.Authentication; +using Microsoft.EntityFrameworkCore; + +namespace API.Endpoints.Effect; + +public class GetEffectRequest +{ + public int Id { get; set; } +} + +public class GetEffectEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Get("/effect/{@id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct) + { + Models.Effect? effect = await appDbContext + .Effects + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (effect == null) + { + Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé."); + await Send.NotFoundAsync(ct); + return; + } + + GetEffectDto responseDto = new() + { + Id = effect.Id, + Label = effect.Label, + }; + await Send.OkAsync(responseDto, ct); + + } +} \ No newline at end of file