Ajouter PyroFetes/Endpoints/Material/CreateMaterialEndpoint

This commit is contained in:
2025-10-08 16:41:53 +02:00
parent 4aa6db31b0
commit 9b9ec133aa

View File

@@ -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<CreateMaterialDto, GetMaterialDto>
{
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);
}
}