Files
CMS/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderQueryHandler.cs

23 lines
792 B
C#
Raw Normal View History

namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
public class GetUserOrderQueryHandler : IRequestHandler<GetUserOrderQuery, GetUserOrderResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserOrderQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserOrderResponseDto> Handle(GetUserOrderQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserOrders
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetUserOrderResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
}
}