From 9b9ec133aa4b2d5ffafee88b99e9910b6e5ef701 Mon Sep 17 00:00:00 2001 From: kieva Date: Wed, 8 Oct 2025 16:41:53 +0200 Subject: [PATCH] Ajouter PyroFetes/Endpoints/Material/CreateMaterialEndpoint --- .../Endpoints/Material/CreateMaterialEndpoint | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 PyroFetes/Endpoints/Material/CreateMaterialEndpoint diff --git a/PyroFetes/Endpoints/Material/CreateMaterialEndpoint b/PyroFetes/Endpoints/Material/CreateMaterialEndpoint new file mode 100644 index 0000000..af9ea50 --- /dev/null +++ b/PyroFetes/Endpoints/Material/CreateMaterialEndpoint @@ -0,0 +1,36 @@ +using API.DTO.Material.Request; +using API.DTO.Material.Response; +using FastEndpoints; +namespace API.Endpoints.Material; + +public class CreateMaterialEndpoint(AppDbContext appDbContext) : Endpoint +{ + public override void Configure() + { + Post("/material/create"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct) + { + Models.Material quantity = new() + { + Name = req.Name, + Quantity = req.Quantity, + WarehouseId = req.WarehouseId, + }; + + appDbContext.Materials.Add(quantity); + await appDbContext.SaveChangesAsync(ct); + Console.WriteLine("Material added"); + + GetMaterialDto responseDto = new() + { + Id = quantity.Id, + WarehouseId = quantity.WarehouseId, + Name = req.Name, + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file