From 9caa30bf60f692370c9227d8b73c76942c52a97a Mon Sep 17 00:00:00 2001 From: Jiwon Date: Tue, 28 Nov 2023 14:18:22 +0900 Subject: [PATCH] [Feature] Implement Acc bulk insert (#2321) * feat: Implement bulk insert * fix method name * fix lint * Fix body parameter * fix lint --- .../AccessControlServiceController.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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) {