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

@@ -3,11 +3,13 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers;
public class UpdateDelivererEndpoint(
PyroFetesDbContext database,
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
{
public override void Configure()
@@ -19,7 +21,7 @@ public class UpdateDelivererEndpoint(
public override async Task HandleAsync(UpdateDelivererDto req, CancellationToken ct)
{
Deliverer? deliverer = await database.Deliverers.SingleOrDefaultAsync(x=>x.Id == req.Id, ct);
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.Id), ct);
if (deliverer == null)
{
@@ -29,7 +31,7 @@ public class UpdateDelivererEndpoint(
deliverer.Transporter = req.Transporter;
await database.SaveChangesAsync(ct);
await deliverersRepository.UpdateAsync(deliverer,ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
}