From 997d7c64fb9659fe9467a9e2bb7c4de8e75639cf Mon Sep 17 00:00:00 2001 From: kieva Date: Wed, 8 Oct 2025 16:35:28 +0200 Subject: [PATCH] Ajouter PyroFetes/Endpoints/Color/CreateColorEndpoint --- PyroFetes/Endpoints/Color/CreateColorEndpoint | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 PyroFetes/Endpoints/Color/CreateColorEndpoint diff --git a/PyroFetes/Endpoints/Color/CreateColorEndpoint b/PyroFetes/Endpoints/Color/CreateColorEndpoint new file mode 100644 index 0000000..c194cea --- /dev/null +++ b/PyroFetes/Endpoints/Color/CreateColorEndpoint @@ -0,0 +1,35 @@ +using API.DTO.Color.Request; +using API.DTO.Color.Response; +using FastEndpoints; + +namespace API.Endpoints.Color; + +public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Post("/color/create"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateColorDto req, CancellationToken ct) + { + Models.Color color = new() + { + Label = req.Label, + }; + + appDbContext.Colors.Add(color); + await appDbContext.SaveChangesAsync(ct); + Console.WriteLine("Added Color"); + + GetColorDto responseDto = new() + { + Id = color.Id, + Label = req.Label, + }; + + await Send.OkAsync(responseDto, ct); + } + +} \ No newline at end of file