Api/Brizco.Repository/Handlers/Sections/GetSectionsQueryHandler.cs

23 lines
1001 B
C#

namespace Brizco.Repository.Handlers.Sections;
public class GetSectionsQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<GetSectionsQuery, List<SectionSDto>>
{
public async Task<List<SectionSDto>> Handle(GetSectionsQuery 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<Section>().TableNoTracking
.Where(s=>s.ComplexId==complexId)
.OrderByDescending(s => s.CreatedAt)
.Skip(request.Page * 15).Take(15)
.Select(SectionMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return shifts;
}
}