using AutoMapper; using MediatR; using ExpenseTracker.Application.Common.Interfaces.Repositories; using ExpenseTracker.Application.Common.Interfaces.Services; namespace ExpenseTracker.Application.Accounts.Queries.Charts.GetExpenseBarChart; public class GetExpenseBarChartQueryHandler : IRequestHandler { private readonly IMapper _mapper; private readonly IAccountRepository _accountRepository; private readonly ITransactionRepository _transactionRepository; private readonly ISessionUserService _sessionUserService; public GetExpenseBarChartQueryHandler( IMapper mapper, IAccountRepository repository, ITransactionRepository transactionRepository, ISessionUserService sessionUserService) { _mapper = mapper; _accountRepository = repository; _sessionUserService = sessionUserService; _transactionRepository = transactionRepository; } public async Task Handle(GetExpenseBarChartQuery request, CancellationToken cancellationToken) { var entities = _transactionRepository.Queryable .Where(e => e.AccountId == request.AccountId && e.Amount < 0) .ToList() .Where(e => DateOnly.FromDateTime(e.Time.DateTime) >= request.FromDate && DateOnly.FromDateTime(e.Time.DateTime) < request.ToDate) .OrderBy(e => e.Time); var groupsByDate = entities.GroupBy(e => e.Time.Date, t => t.Amount); return new DailyTransactionsBarChart(groupsByDate, request.FromDate, request.ToDate); } }