autobus-api_old/AutobusApi.Application/Employees/Queries/GetEmployeesWithPagination/GetEmployeesWithPaginationQueryHandler.cs

33 lines
1.1 KiB
C#

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.Employees.Queries.GetEmployeesWithPagination;
public class GetEmployeesWithPaginationQueryHandler : IRequestHandler<GetEmployeesWithPaginationQuery, PaginatedList<EmployeeDto>>
{
private readonly IApplicationDbContext _dbContext;
private readonly IMapper _mapper;
public GetEmployeesWithPaginationQueryHandler(
IApplicationDbContext dbContext,
IMapper mapper)
{
_dbContext = dbContext;
_mapper = mapper;
}
public async Task<PaginatedList<EmployeeDto>> Handle(
GetEmployeesWithPaginationQuery request,
CancellationToken cancellationToken)
{
return await _dbContext.Employees
.ProjectTo<EmployeeDto>(_mapper.ConfigurationProvider)
.ApplySort(request.Sort)
.PaginatedListAsync(request.PageNumber, request.PageSize);
}
}