This commit is contained in:
2023-07-21 21:06:45 +03:00
parent 2f108bef4f
commit fa5a8a9001
37 changed files with 2319 additions and 28 deletions
@@ -0,0 +1,55 @@
namespace MyOffice.Services.Dashboard;
using MyOffice.Services.Dashboard.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core.Extensions;
using Data.Repositories.Account;
using Data.Repositories.Currency;
public class DashboardService
{
private readonly IAccountRepository _accountRepository;
private readonly ICurrencyRateRepository _currencyRateRepository;
public DashboardService(
IAccountRepository accountRepository,
ICurrencyRateRepository currencyRateRepository
)
{
_accountRepository = accountRepository;
_currencyRateRepository = currencyRateRepository;
}
public DashboardData GetDashboardRestData(Guid userId)
{
var lastDaysStart = DateTime.UtcNow.AddDays(-7).StartOfDay();
var lastDaysEnd = lastDaysStart.AddDays(7).EndOfDay();
var previousDaysStart = lastDaysStart.AddDays(-7).StartOfDay();
var previousDaysEnd = previousDaysStart.AddDays(7).EndOfDay();
var rests = _accountRepository.GetRestAtDate(userId, DateTime.UtcNow);
var currencyIds = rests
.Select(x => x.CurrencyId)
.Distinct()
.ToList();
var lastrates = _currencyRateRepository.GetLastRates(currencyIds);
foreach (var rest in rests)
{
//var rate = lastrates.FirstOrDefault(x => x.CurrencyId == rest.CurrencyId)
}
return new DashboardData
{
IncomeLastWeek = _accountRepository.GetPeriodIncome(userId, lastDaysStart, lastDaysEnd),
IncomePreviousWeek = _accountRepository.GetPeriodIncome(userId, previousDaysStart, previousDaysEnd),
OutcomeLastWeek = _accountRepository.GetPeriodOutcome(userId, lastDaysStart, lastDaysEnd),
OutcomePreviousWeek = _accountRepository.GetPeriodOutcome(userId, previousDaysStart, previousDaysEnd),
Rests = rests,
};
}
}