Api/Brizco.Repository/Handlers/ShiftPlan/GetShiftPlanQueryHandler.cs

22 lines
877 B
C#

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