forked from sanchezvem/PyroFetes
09/10
This commit is contained in:
36
PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using PyroFetes.DTO.Material.Request;
|
||||
using PyroFetes.DTO.Material.Response;
|
||||
using FastEndpoints;
|
||||
namespace PyroFetes.Endpoints.Material;
|
||||
|
||||
public class CreateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/material/create");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Material material = new()
|
||||
{
|
||||
Label = req.Label,
|
||||
Quantity = req.Quantity,
|
||||
WarehouseId = req.WarehouseId,
|
||||
};
|
||||
|
||||
appDbContext.Materials.Add(material);
|
||||
await appDbContext.SaveChangesAsync(ct);
|
||||
Console.WriteLine("Material added");
|
||||
|
||||
GetMaterialDto responseDto = new()
|
||||
{
|
||||
Id = material.Id,
|
||||
WarehouseId = material.WarehouseId,
|
||||
Label = req.Label,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user