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