Api/Berizco.Repository/Handlers/Shift/GetShiftQueryHandler.cs

22 lines
837 B
C#

namespace Brizco.Repository.Handlers.Shift;
public class GetShiftPlanQueryHandler : IRequestHandler<GetShiftQuery, ShiftSDto>
{
private readonly IRepositoryWrapper _repositoryWrapper;
public GetShiftPlanQueryHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<ShiftSDto> Handle(GetShiftQuery request, CancellationToken cancellationToken)
{
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
.TableNoTracking
.Where(s => s.Id == request.id)
.Select(ShiftMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if (shift == null)
throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
return shift;
}
}