diff --git a/NineChronicles.Headless.AccessControlCenter/Controllers/AccessControlServiceController.cs b/NineChronicles.Headless.AccessControlCenter/Controllers/AccessControlServiceController.cs index 40117f900..5b2f0f303 100644 --- a/NineChronicles.Headless.AccessControlCenter/Controllers/AccessControlServiceController.cs +++ b/NineChronicles.Headless.AccessControlCenter/Controllers/AccessControlServiceController.cs @@ -10,6 +10,13 @@ namespace NineChronicles.Headless.AccessControlCenter.Controllers [ApiController] public class AccessControlServiceController : ControllerBase { + public class BulkAddTxQuotaInput + { + public List Addresses { get; set; } = new List(); + + public int Quota { get; set; } + } + private readonly IMutableAccessControlService _accessControlService; public AccessControlServiceController(IMutableAccessControlService accessControlService) @@ -23,8 +30,8 @@ public AccessControlServiceController(IMutableAccessControlService accessControl return _accessControlService.GetTxQuota(new Address(address)); } - [HttpPost("entries/add-tx-quota/{address}/{quota:int}")] - public ActionResult AddTxQuota(string address, int quota) + [HttpPost("entries/add-tx-quota/{address}")] + public ActionResult AddTxQuota(string address, [FromBody] int quota) { var maxQuota = 10; if (quota > maxQuota) @@ -36,6 +43,27 @@ public ActionResult AddTxQuota(string address, int quota) return Ok(); } + [HttpPost("entries/bulk-add-tx-quota")] + public ActionResult BulkAddTxQuota([FromBody] BulkAddTxQuotaInput bulkAddTxQuotaInput) + { + var maxQuota = 10; + var maxAddressCount = 100; + if (bulkAddTxQuotaInput.Quota > maxQuota) + { + return BadRequest($"The quota cannot exceed {maxQuota}."); + } + if (bulkAddTxQuotaInput.Addresses.Count > maxAddressCount) + { + return BadRequest($"The addresses cannot exceed {maxAddressCount}."); + } + + foreach (string address in bulkAddTxQuotaInput.Addresses) + { + _accessControlService.AddTxQuota(new Address(address), bulkAddTxQuotaInput.Quota); + } + return Ok(); + } + [HttpPost("entries/remove-tx-quota/{address}")] public ActionResult RemoveTxQuota(string address) {