-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show current quota usage on Identity View (#367)
* feat: progress bar and hardcoded usage values * feat: make API return actual quota usage * fix: tests missing new DI factory * fix: bad quota tag * refactor: rename var * refactor: remove needless line * refactor: move metricCalculatorFactoryfake creation to CreateHandler * refactor: simplify Handler with GetIdentityResponse.Create * refactor: move extraction of quota attributes to QuotaDTO ctor * refactor: rename mock/stub. Use Dummy instead of Fake * Trigger Build * refactor: create overload for CreateHandler This way we abstract the creation of optional dummies --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
55bf9a5
commit 2fae67e
Showing
8 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 27 additions & 23 deletions
50
Modules/Quotas/src/Quotas.Application/Identities/Queries/GetIdentity/GetIdentityResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
using Backbone.Modules.Quotas.Application.DTOs; | ||
using Backbone.Modules.Quotas.Domain.Aggregates.Identities; | ||
using Backbone.Modules.Quotas.Domain.Aggregates.Metrics; | ||
using Backbone.Modules.Quotas.Domain.Metrics; | ||
|
||
namespace Backbone.Modules.Quotas.Application.Identities.Queries.GetIdentity; | ||
public class GetIdentityResponse | ||
{ | ||
public GetIdentityResponse(string identityAddress, IEnumerable<TierQuota> tierQuotas, IEnumerable<IndividualQuota> individualQuotas, IEnumerable<Metric> metrics) | ||
public string Address { get; set; } | ||
public IEnumerable<QuotaDTO> Quotas { get; set; } | ||
|
||
public static async Task<GetIdentityResponse> Create(MetricCalculatorFactory metricCalculatorFactory, string identityAddress, IEnumerable<TierQuota> tierQuotas, IEnumerable<IndividualQuota> individualQuotas, IEnumerable<Metric> metrics, CancellationToken cancellationToken) | ||
{ | ||
var quotasList = new List<QuotaDTO>(); | ||
quotasList.AddRange(individualQuotas.Select(q => | ||
new QuotaDTO( | ||
q.Id, | ||
QuotaSource.Individual, | ||
new MetricDTO(metrics.First(m => m.Key == q.MetricKey)), | ||
q.Max, | ||
q.Period.ToString() | ||
) | ||
)); | ||
quotasList.AddRange(tierQuotas.Select(q => | ||
new QuotaDTO( | ||
q.Id, | ||
QuotaSource.Tier, | ||
new MetricDTO(metrics.First(m => m.Key == q.MetricKey)), | ||
q.Max, | ||
q.Period.ToString() | ||
) | ||
)); | ||
|
||
Address = identityAddress; | ||
Quotas = quotasList; | ||
var allQuotas = (individualQuotas as IEnumerable<Quota>).Union(tierQuotas); | ||
|
||
foreach (var quota in allQuotas) | ||
{ | ||
var usage = await CalculateUsage(metricCalculatorFactory, quota, identityAddress, cancellationToken); | ||
quotasList.Add(new QuotaDTO( | ||
quota, | ||
new MetricDTO(metrics.First(m => m.Key == quota.MetricKey)), | ||
usage | ||
)); | ||
} | ||
|
||
return new GetIdentityResponse() | ||
{ | ||
Address = identityAddress, | ||
Quotas = quotasList | ||
}; | ||
} | ||
|
||
public string Address { get; set; } | ||
public IEnumerable<QuotaDTO> Quotas { get; set; } | ||
private static async Task<uint> CalculateUsage(MetricCalculatorFactory metricCalculatorFactory, Quota quota, string identityAddress, CancellationToken cancellationToken) | ||
{ | ||
var calculator = metricCalculatorFactory.CreateFor(quota.MetricKey); | ||
return await calculator.CalculateUsage(quota.Period.CalculateBegin(), quota.Period.CalculateEnd(), identityAddress, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters