using NetinaCMS.Repository.Repositories.Base.Contracts;

namespace NetinaCMS.Repository.Handlers.BlogCategories;

public class GetBlogCategoriesQueryHandler : IRequestHandler<GetBlogCategoriesQuery,List<BlogCategorySDto>>
{
    private readonly IRepositoryWrapper _repositoryWrapper;

    public GetBlogCategoriesQueryHandler(IRepositoryWrapper repositoryWrapper)
    {
        _repositoryWrapper = repositoryWrapper;
    }
    public async Task<List<BlogCategorySDto>> Handle(GetBlogCategoriesQuery request, CancellationToken cancellationToken)
    {
        return await _repositoryWrapper.SetRepository<BlogCategory>()
            .TableNoTracking
            .Skip(request.Page * 20)
            .Take(20)
            .Select(BlogCategoryMapper.ProjectToSDto)
            .ToListAsync(cancellationToken);

    }
}