forked from sanchezvem/PyroFetes
Ajouter PyroFetes/Endpoints/Material/CreateMaterialEndpoint
This commit is contained in:
36
PyroFetes/Endpoints/Material/CreateMaterialEndpoint
Normal file
36
PyroFetes/Endpoints/Material/CreateMaterialEndpoint
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user