forked from sanchezvem/PyroFetes
Adapted Deliverer endpoints with repository spec and automapper
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user