From 0e3e8dc9885caf72e923eb6d1bd4bb476ed1e55d Mon Sep 17 00:00:00 2001 From: Kleissner Date: Wed, 1 Jun 2022 17:09:42 +0200 Subject: [PATCH] Webapi: Implement pagination for /search/result by adding optional &offset= parameter --- webapi/Search.go | 9 ++++++++- webapi/readme.md | 17 +++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/webapi/Search.go b/webapi/Search.go index 1a0a2e8..0e61360 100644 --- a/webapi/Search.go +++ b/webapi/Search.go @@ -122,6 +122,7 @@ Optional parameters: &sizemin=[Minimum file size] &sizemax=[Maximum file size] &sort=[sort order] + &offset=[absolute offset] with &limit=[records] to get items pagination style. Returned items (and ones before) are automatically frozen. Result: 200 with JSON structure SearchResult. Check the field status. */ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Request) { @@ -135,6 +136,7 @@ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Reques if err != nil { limit = 100 } + offset, errOffset := strconv.Atoi(r.Form.Get("offset")) // find the job ID job := api.JobLookup(jobID) @@ -159,7 +161,12 @@ func (api *WebapiInstance) apiSearchResult(w http.ResponseWriter, r *http.Reques } // query all results - resultFiles := job.ReturnNext(limit) + var resultFiles []*apiFile + if errOffset == nil { + resultFiles = job.ReturnResult(offset, limit) + } else { + resultFiles = job.ReturnNext(limit) + } var result SearchResult result.Files = []apiFile{} diff --git a/webapi/readme.md b/webapi/readme.md index f5e9da1..2c9970b 100644 --- a/webapi/readme.md +++ b/webapi/readme.md @@ -688,14 +688,15 @@ Note that the date format for the `&from=` and `&to=` parameters is "2006-01-02 ``` Request: GET /search/result?id=[UUID]&limit=[max records] - Optional parameters: - &reset=[0|1] to reset the filters or sort orders with any of the below parameters (all required): - &filetype=[File Type] - &fileformat=[File Format] - &from=[Date From]&to=[Date To] - &sizemin=[Minimum file size] - &sizemax=[Maximum file size] - &sort=[sort order] +Optional parameters: + &reset=[0|1] to reset the filters or sort orders with any of the below parameters (all required): + &filetype=[File Type] + &fileformat=[File Format] + &from=[Date From]&to=[Date To] + &sizemin=[Minimum file size] + &sizemax=[Maximum file size] + &sort=[sort order] + &offset=[absolute offset] with &limit=[records] to get items pagination style. Returned items (and ones before) are automatically frozen. Result: 200 with JSON structure SearchResult. Check the field status. ```