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

23 lines
1001 B
C#
Raw Normal View History

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