Api/Brizco.Repository/Handlers/Shift/GetShiftsQueryHandler.cs

30 lines
1.2 KiB
C#
Raw Normal View History

2023-09-15 12:37:02 +03:30
namespace Brizco.Repository.Handlers.Shift;
public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<ShiftSDto>>
2023-09-15 12:37:02 +03:30
{
private readonly IRepositoryWrapper _repositoryWrapper;
2023-11-14 16:21:49 +03:30
private readonly ICurrentUserService _currentUserService;
2023-09-15 12:37:02 +03:30
2023-11-14 16:21:49 +03:30
public GetShiftPlansQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
2023-09-15 12:37:02 +03:30
{
_repositoryWrapper = repositoryWrapper;
2023-11-14 16:21:49 +03:30
_currentUserService = currentUserService;
2023-09-15 12:37:02 +03:30
}
public async Task<List<ShiftSDto>> Handle(GetShiftsQuery request, CancellationToken cancellationToken)
{
2023-11-14 16:21:49 +03:30
if (_currentUserService.ComplexId == null)
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
if (!Guid.TryParse(_currentUserService.ComplexId, out Guid complexId))
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
2023-09-15 12:37:02 +03:30
var shifts = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>().TableNoTracking
2023-11-14 16:21:49 +03:30
.Where(s=>s.ComplexId==complexId)
2023-09-15 12:37:02 +03:30
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(ShiftMapper.ProjectToSDto)
2023-09-15 12:37:02 +03:30
.ToListAsync(cancellationToken);
2023-09-15 12:37:02 +03:30
return shifts;
}
}