using AutoMapper; using MediatR; using ExpenseTracker.Application.Common.Interfaces.Repositories; using ExpenseTracker.Application.Common.Interfaces.Services; namespace ExpenseTracker.Application.Accounts.Queries.Charts.GetProfitBarChart; public class GetProfitBarChartQueryHandler : IRequestHandler { private readonly IMapper _mapper; private readonly IAccountRepository _accountRepository; private readonly ITransactionRepository _transactionRepository; private readonly ISessionUserService _sessionUserService; public GetProfitBarChartQueryHandler( IMapper mapper, IAccountRepository repository, ITransactionRepository transactionRepository, ISessionUserService sessionUserService) { _mapper = mapper; _accountRepository = repository; _sessionUserService = sessionUserService; _transactionRepository = transactionRepository; } public async Task Handle(GetProfitBarChartQuery request, CancellationToken cancellationToken) { var entities = _transactionRepository.Queryable .Where(e => e.AccountId == request.AccountId) .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); } }