Refactored Supplier

This commit is contained in:
Cristiano
2025-11-20 15:11:14 +01:00
parent 8325aa0768
commit d64890dec9
6 changed files with 37 additions and 74 deletions

View File

@@ -1,10 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Suppliers;
public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetSupplierDto>>
public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) : EndpointWithoutRequest<List<GetSupplierDto>>
{
public override void Configure()
{
@@ -14,19 +15,6 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWith
public override async Task HandleAsync(CancellationToken ct)
{
List<GetSupplierDto> supplier = await database.Suppliers
.Select(supplier => new GetSupplierDto()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
}).ToListAsync(ct);
await Send.OkAsync(supplier, ct);
await Send.OkAsync(await suppliersRepository.ProjectToListAsync<GetSupplierDto>(ct), ct);
}
}