24 lines
1.0 KiB
C#
24 lines
1.0 KiB
C#
namespace Brizco.Repository.Handlers.Routines;
|
|
|
|
public class GetRoutinesQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
|
: IRequestHandler<GetRoutinesQuery, List<RoutineSDto>>
|
|
{
|
|
public async Task<List<RoutineSDto>> Handle(GetRoutinesQuery 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 entities = await repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>().TableNoTracking
|
|
.Where(p=>p.ComplexId==complexId)
|
|
.OrderByDescending(s => s.CreatedAt)
|
|
.Skip(request.Page * 15).Take(15)
|
|
.Select(RoutineMapper.ProjectToSDto)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
|
|
return entities;
|
|
}
|
|
} |