Skip to content

Commit

Permalink
Merge pull request #39 from pavel-zhur/feature/onedog-billing-by-cate…
Browse files Browse the repository at this point in the history
…gory

billing by category
  • Loading branch information
pavel-zhur authored Jul 16, 2024
2 parents 46b4405 + 8cb3239 commit 418e0b2
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ protected override async Task ExecuteQuickly()
private async Task ExecuteBackground()
{
var all = await _billingApiClient.All(ScopeAwareness.DomainId);
var total = all.Usages.Where(x => x.Price.HasValue).Sum(x => x.Price);
if (total is 0 or null)
var totals = all.Usages
.Where(x => x.Price > 0)
.GroupBy(x => x.Category ?? "unknown")
.ToDictionary(x => x.Key, x => x.Sum(x => x.Price!.Value));

if (!totals.Any())
{
Io.WriteLine("Пока ничего нет.");
return;
}

var domain = await _dogDatabase.Domains.SingleAsync(x => x.Id == ScopeAwareness.DomainId);

Io.WriteLine($"Использовано {total * (domain.BillingRatio ?? 1):C}.");
foreach (var total in totals)
{
Io.WriteLine($"Использовано {total.Key} {total.Value * (domain.BillingRatio ?? 1):C}.");
}
}
}

0 comments on commit 418e0b2

Please sign in to comment.