Api/Brizco.Repository/Handlers/Routines/GetRoutinesQueryHandler.cs

24 lines
1.0 KiB
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Routines;
2023-11-14 16:21:49 +03:30
2024-08-09 21:42:04 +03:30
public class GetRoutinesQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
: IRequestHandler<GetRoutinesQuery, List<RoutineSDto>>
2023-11-14 16:21:49 +03:30
{
public async Task<List<RoutineSDto>> Handle(GetRoutinesQuery 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 entities = await repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>().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(RoutineMapper.ProjectToSDto)
.ToListAsync(cancellationToken);
return entities;
}
}