Adapted Deliverer endpoints with repository spec and automapper

This commit is contained in:
Cristiano
2025-11-13 15:26:22 +01:00
parent 60a7c059b4
commit c6d4ef2c58
7 changed files with 38 additions and 23 deletions

View File

@@ -2,10 +2,11 @@ using AutoMapper.QueryableExtensions;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Deliverers;
public class GetAllDelivererEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetDelivererDto>>
public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository) : EndpointWithoutRequest<List<GetDelivererDto>>
{
public override void Configure()
{
@@ -16,13 +17,7 @@ public class GetAllDelivererEndpoint(PyroFetesDbContext database) : EndpointWith
public override async Task HandleAsync(CancellationToken ct)
{
List<GetDelivererDto> deliverers = await database.Deliverers.Select(x => new GetDelivererDto()
{
Id = x.Id,
Transporter = x.Transporter,
}).ToListAsync(ct);
await Send.OkAsync(deliverers, ct);
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
}
}