Api/Netina.Repository/Handlers/Orders/GetOrderLDtoQueryHandler.cs

21 lines
799 B
C#

using Netina.Domain.Entities.Orders;
namespace Netina.Repository.Handlers.Orders;
public class GetOrderLDtoQueryHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<GetOrderLDtoQuery, OrderLDto>
{
public async Task<OrderLDto> Handle(GetOrderLDtoQuery request, CancellationToken cancellationToken)
{
if (request.Id == default)
throw new AppException("Order id is null");
var order = await repositoryWrapper.SetRepository<Order>()
.TableNoTracking
.Where(o => o.Id == request.Id)
.Select(OrderMapper.ProjectToLDto)
.FirstOrDefaultAsync(cancellationToken);
if (order == null)
throw new AppException("Order not found", ApiResultStatusCode.NotFound);
return order;
}
}