Creating supplier's endpoints

This commit is contained in:
2025-11-06 17:30:03 +01:00
parent 1c898f9144
commit be0a6a4004
6 changed files with 235 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Supplier;
public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<CreateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
Post("/api/suppliers");
}
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
{
var supplier = new Models.Supplier()
{
Name = req.Name,
Email = req.Email,
Phone = req.Phone,
Address = req.Address,
City = req.City,
ZipCode = req.ZipCode,
DeliveryDelay = req.DeliveryDelay
};
database.Suppliers.Add(supplier);
await database.SaveChangesAsync(ct);
GetSupplierDto responseDto = new()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
};
await Send.OkAsync(responseDto, ct);
}
}