From b224f69b69f0391ddf37866a9a880d0f86637c70 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Sat, 20 Jul 2024 15:28:19 -0400 Subject: [PATCH 1/2] chore: Update URL pagination endpoint to always return 20 results Previously, it would always return 0 results, which was confusing. For testing purposes, it shouldn't matter that the results are repeated in this context. --- internal/pagination/service.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/pagination/service.go b/internal/pagination/service.go index 99c48fa..cd5019a 100644 --- a/internal/pagination/service.go +++ b/internal/pagination/service.go @@ -158,6 +158,11 @@ func HandleURL(w http.ResponseWriter, r *http.Request) { ResultArray: make([]interface{}, 0), } + // Just always return the same 20 results + for i := 0; i < total; i++ { + res.ResultArray = append(res.ResultArray, i) + } + if attempts > 1 { baseURL := fmt.Sprintf("%s://%s", r.URL.Scheme, r.Host) if r.URL.Scheme == "" { // Fallback if Scheme is not available From 21ac6ca5cb402297768e26872ca75712f72ebf4f Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 22 Jul 2024 10:15:42 -0400 Subject: [PATCH 2/2] chore: Return more interesting /pagination/url results ```console $ curl -XGET 'http://localhost:8080/pagination/url?attempts=3' {"numPages":0,"resultArray":[0,1,2,3,4,5,6,7,8],"next":"http://localhost:8080/pagination/url?attempts=2"} $ curl -XGET 'http://localhost:8080/pagination/url?attempts=2' {"numPages":0,"resultArray":[0,1,2,3,4,5],"next":"http://localhost:8080/pagination/url?attempts=1"} $ curl -XGET 'http://localhost:8080/pagination/url?attempts=1' {"numPages":0,"resultArray":[0,1,2]} $ curl -XGET 'http://localhost:8080/pagination/url?attempts=0' {"numPages":0,"resultArray":[]} ``` --- internal/pagination/service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pagination/service.go b/internal/pagination/service.go index cd5019a..45af218 100644 --- a/internal/pagination/service.go +++ b/internal/pagination/service.go @@ -158,8 +158,8 @@ func HandleURL(w http.ResponseWriter, r *http.Request) { ResultArray: make([]interface{}, 0), } - // Just always return the same 20 results - for i := 0; i < total; i++ { + // Return 9, 6, then 3 results for 18 total results. + for i := 0; i < total && len(res.ResultArray) < (attempts*3); i++ { res.ResultArray = append(res.ResultArray, i) }