Api/Brizco.Repository/Handlers/Positions/GetPositionsQueryHandler.cs

31 lines
1.2 KiB
C#

namespace Brizco.Repository.Handlers.Positions;
public class GetPositionsQueryHandler : IRequestHandler<GetPositionsQuery, List<PositionSDto>>
{
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly ICurrentUserService _currentUserService;
public GetPositionsQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
{
_repositoryWrapper = repositoryWrapper;
_currentUserService = currentUserService;
}
public async Task<List<PositionSDto>> Handle(GetPositionsQuery request, CancellationToken cancellationToken)
{
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);
var shifts = await _repositoryWrapper.SetRepository<Position>().TableNoTracking
.Where(p=>p.ComplexId==complexId)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(PositionMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return shifts;
}
}