-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathResetQuotaMutation.cs
More file actions
47 lines (39 loc) · 1.34 KB
/
Copy pathResetQuotaMutation.cs
File metadata and controls
47 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using BillingQuotas.State;
using ModularityKit.Mutator.Abstractions.Changes;
using ModularityKit.Mutator.Abstractions.Context;
using ModularityKit.Mutator.Abstractions.Engine;
using ModularityKit.Mutator.Abstractions.Intent;
using ModularityKit.Mutator.Abstractions.Results;
namespace BillingQuotas.Mutations;
/// <summary>
/// Mutation that resets user's quota to zero.
/// </summary>
internal sealed class ResetQuotaMutation(
string userId,
MutationContext context
) : MutationBase<QuotaState>(
CreateIntent(
operationName: "ResetQuota",
category: "Billing",
description: "Reset user quota to zero",
riskLevel: MutationRiskLevel.High),
context)
{
public string UserId { get; } = userId;
public override ValidationResult Validate(QuotaState state)
{
var result = new ValidationResult();
if (string.IsNullOrEmpty(UserId))
result.AddError("UserId", "UserId cannot be empty");
return result;
}
public override MutationResult<QuotaState> Apply(QuotaState state)
{
var quotas = state.UserQuotas.ToDictionary(kv => kv.Key, kv => kv.Value);
quotas[UserId] = 0;
var newState = state with { UserQuotas = quotas };
return Success(
newState,
StateChange.Modified($"UserQuotas.{UserId}", null, 0));
}
}