namespace Brizco.Repository.Handlers.Activity;

public class GetActivitiesQueryHandler : IRequestHandler<GetActivitiesQuery, List<ActivitySDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetActivitiesQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<List<ActivitySDto>> Handle(GetActivitiesQuery request, CancellationToken cancellationToken)
    {
        var tasks = await _repositoryWrapper.SetRepository<Domain.Entities.Task.Activity>().TableNoTracking
            .OrderByDescending(s => s.CreatedAt)
            .Skip(request.Page * 15).Take(15)
            .Select(ActivityMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);

        return tasks;
    }
}