Skip to content

Commit

Permalink
[Feature] Implement Acc bulk insert (#2321)
Browse files Browse the repository at this point in the history
* feat: Implement bulk insert

* fix method name

* fix lint

* Fix body parameter

* fix lint
  • Loading branch information
Atralupus authored Nov 28, 2023
1 parent 8aa2d98 commit 9caa30b
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace NineChronicles.Headless.AccessControlCenter.Controllers
[ApiController]
public class AccessControlServiceController : ControllerBase
{
public class BulkAddTxQuotaInput
{
public List<string> Addresses { get; set; } = new List<string>();

public int Quota { get; set; }
}

private readonly IMutableAccessControlService _accessControlService;

public AccessControlServiceController(IMutableAccessControlService accessControlService)
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down

0 comments on commit 9caa30b

Please sign in to comment.