namespace Brizco.Repository.Handlers.Task;

public class GetActivitiesQueryHandler : IRequestHandler<GetTasksQuery, List<TaskSDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

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

        return tasks;
    }
}