From 8fed8f77ad765fa08906430133e98716905d72a5 Mon Sep 17 00:00:00 2001 From: Troy Anderson <33005486+TheHazeEffect@users.noreply.github.com> Date: Sun, 31 Oct 2021 05:47:12 -0500 Subject: [PATCH] PR for Issue #3038 adds params for getInvoices pagination (#3039) * ##3038 add pagination elements * correct skip to take * updated swagger docs * set take nullable to true --- .../BTCPayServerClient.Invoices.cs | 10 ++++++++++ .../GreenField/InvoiceController.cs | 7 ++++++- .../GreenField/LocalBTCPayServerClient.cs | 8 ++++++-- .../swagger/v1/swagger.template.invoices.json | 20 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Client/BTCPayServerClient.Invoices.cs b/BTCPayServer.Client/BTCPayServerClient.Invoices.cs index 38987cbd1..c4450b7e8 100644 --- a/BTCPayServer.Client/BTCPayServerClient.Invoices.cs +++ b/BTCPayServer.Client/BTCPayServerClient.Invoices.cs @@ -17,6 +17,8 @@ namespace BTCPayServer.Client DateTimeOffset? endDate = null, string textSearch = null, bool includeArchived = false, + int? skip = null, + int? take = null, CancellationToken token = default) { Dictionary queryPayload = new Dictionary(); @@ -34,6 +36,14 @@ namespace BTCPayServer.Client queryPayload.Add(nameof(textSearch), textSearch); if (status != null) queryPayload.Add(nameof(status), status.Select(s=> s.ToString().ToLower()).ToArray()); + + if(skip != null) { + queryPayload.Add(nameof(skip), skip); + } + + if(take != null) { + queryPayload.Add(nameof(take), take); + } var response = await _httpClient.SendAsync( diff --git a/BTCPayServer/Controllers/GreenField/InvoiceController.cs b/BTCPayServer/Controllers/GreenField/InvoiceController.cs index 126bd7432..734ffd526 100644 --- a/BTCPayServer/Controllers/GreenField/InvoiceController.cs +++ b/BTCPayServer/Controllers/GreenField/InvoiceController.cs @@ -57,7 +57,10 @@ namespace BTCPayServer.Controllers.GreenField [ModelBinder(typeof(ModelBinders.DateTimeOffsetModelBinder))] DateTimeOffset? endDate = null, [FromQuery] string textSearch = null, - [FromQuery] bool includeArchived = false) + [FromQuery] bool includeArchived = false, + [FromQuery] int? skip = null, + [FromQuery] int? take = null + ) { var store = HttpContext.GetStoreData(); if (store == null) @@ -77,6 +80,8 @@ namespace BTCPayServer.Controllers.GreenField var invoices = await _invoiceRepository.GetInvoices(new InvoiceQuery() { + Skip = skip, + Take = take, StoreId = new[] {store.Id}, IncludeArchived = includeArchived, StartDate = startDate, diff --git a/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs b/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs index 800f81083..c09ef4272 100644 --- a/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs +++ b/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs @@ -823,12 +823,16 @@ namespace BTCPayServer.Controllers.GreenField DateTimeOffset? endDate = null, string textSearch = null, bool includeArchived = false, - CancellationToken token = default) + int? skip = null, + int? take = null, + CancellationToken token = default + + ) { return GetFromActionResult>( await _greenFieldInvoiceController.GetInvoices(storeId, orderId, status?.Select(invoiceStatus => invoiceStatus.ToString())?.ToArray(), startDate, - endDate, textSearch, includeArchived)); + endDate, textSearch, includeArchived,skip,take)); } public override async Task GetInvoice(string storeId, string invoiceId, diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.invoices.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.invoices.json index 17510b1c7..f247f8981 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.invoices.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.invoices.json @@ -58,6 +58,26 @@ "required": false, "description": "End date of the period to retrieve invoices", "$ref": "#/components/schemas/UnixTimestamp" + }, + { + "name": "skip", + "in": "query", + "required": false, + "description": "Number of records to skip", + "schema": { + "nullable": true, + "type": "number" + } + }, + { + "name": "take", + "in": "query", + "required": false, + "description": "Number of records returned in response", + "schema": { + "nullable": true, + "type": "number" + } } ], "description": "View information about the existing invoices",