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