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

24 lines
1010 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Positions;
2023-11-14 16:21:49 +03:30
2024-08-09 21:42:04 +03:30
public class GetPositionsQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<GetPositionsQuery, List<PositionSDto>>
2023-11-14 16:21:49 +03:30
{
public async Task<List<PositionSDto>> Handle(GetPositionsQuery request, CancellationToken cancellationToken)
{
2024-08-09 21:42:04 +03:30
if (currentUserService.ComplexId == null)
2023-11-14 16:21:49 +03:30
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
2024-08-09 21:42:04 +03:30
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
2023-11-14 16:21:49 +03:30
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
2024-08-09 21:42:04 +03:30
var shifts = await repositoryWrapper.SetRepository<Position>().TableNoTracking
2023-11-14 16:21:49 +03:30
.Where(p=>p.ComplexId==complexId)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(PositionMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return shifts;
}
}