using AutoMapper; using MediatR; using ExpenseTracker.Application.Common.Extensions; using ExpenseTracker.Application.Common.Interfaces.Repositories; using ExpenseTracker.Application.Common.Interfaces.Services; using ExpenseTracker.Application.Common.Models; using ExpenseTracker.Domain.Entities; namespace ExpenseTracker.Application.Accounts.Queries.GetWithPagination; public class GetAccountssWithPaginationQueryHandler : IRequestHandler> { private readonly IMapper _mapper; private readonly IAccountRepository _accountRepository; private readonly ITransactionRepository _transactionRepository; private readonly ISessionUserService _sessionUserService; public GetAccountssWithPaginationQueryHandler( IMapper mapper, IAccountRepository repository, ITransactionRepository transactionRepository, ISessionUserService sessionUserService) { _mapper = mapper; _accountRepository = repository; _sessionUserService = sessionUserService; _transactionRepository = transactionRepository; } public async Task> Handle(GetAccountsWithPaginationQuery request, CancellationToken cancellationToken) { var entities = _accountRepository.Queryable; if (!request.GetAll) { entities = entities.Where(e => e.UserId == _sessionUserService.Id); } return entities .ProjectToPaginatedList(request.PageNumber, request.PageSize, _mapper.ConfigurationProvider); } }