forked from gongxuegit/tiku-backend.net
feat(saas): implement marketplace and tenant onboarding
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
namespace Tiku.Application.Security;
|
||||
|
||||
public static class FeatureQuotaConsumptionExtensions
|
||||
{
|
||||
public static async Task<bool> ConsumeQuotaIfConfiguredAsync(
|
||||
this IFeatureAccessService featureAccessService,
|
||||
Guid tenantId,
|
||||
string metricCode,
|
||||
long amount = 1,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var configured = (await featureAccessService.GetQuotaSummaryAsync(tenantId, cancellationToken))
|
||||
.Any(item => string.Equals(item.MetricCode, metricCode, StringComparison.Ordinal));
|
||||
if (!configured)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!await featureAccessService.TryConsumeQuotaAsync(tenantId, metricCode, amount, cancellationToken))
|
||||
{
|
||||
throw new FeatureAccessException("The tenant feature quota has been exhausted.", "feature_quota_exhausted");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user