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

24 lines
1010 B
C#

namespace Brizco.Repository.Handlers.Positions;
public class GetPositionsQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<GetPositionsQuery, List<PositionSDto>>
{
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;
}
}