Api/Brizco.Repository/Handlers/Routines/GetRoutineQueryHandler.cs

23 lines
852 B
C#

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