namespace Netina.Repository.Handlers.Marketers;

public class GetMarketersQueryHandler(IRepositoryWrapper repositoryWrapper)
    : IRequestHandler<GetMarketersQuery, List<MarketerSDto>>
{
    public async Task<List<MarketerSDto>> Handle(GetMarketersQuery request, CancellationToken cancellationToken)
    {
        var query = repositoryWrapper.SetRepository<Marketer>()
            .TableNoTracking;

        return await query.OrderByDescending(q => q.CreatedAt)
            .Skip(request.Page * 20)
            .Take(20)
            .Select(MarketerMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);
    }
}