using AutobusApi.Application.Common.Interfaces; using AutobusApi.Application.Common.Mappings; using AutobusApi.Application.Common.Models; using AutoMapper; using AutoMapper.QueryableExtensions; using MediatR; namespace AutobusApi.Application.Cities.Queries.GetCitiesWithPagination; public class GetCitiesWithPaginationQueryHandler : IRequestHandler> { private readonly IApplicationDbContext _dbContext; private readonly IMapper _mapper; public GetCitiesWithPaginationQueryHandler( IApplicationDbContext dbContext, IMapper mapper) { _dbContext = dbContext; _mapper = mapper; } public async Task> Handle( GetCitiesWithPaginationQuery request, CancellationToken cancellationToken) { return await _dbContext.Cities .ProjectTo(_mapper.ConfigurationProvider) .ApplySort(request.Sort) .PaginatedListAsync(request.PageNumber, request.PageSize); } }