Skip to content

Commit bf8ac67

Browse files
authored
chore: Update URL pagination endpoint to return 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. After this change: ```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":[]} ```
2 parents 135c690 + 21ac6ca commit bf8ac67

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/pagination/service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
158158
ResultArray: make([]interface{}, 0),
159159
}
160160

161+
// Return 9, 6, then 3 results for 18 total results.
162+
for i := 0; i < total && len(res.ResultArray) < (attempts*3); i++ {
163+
res.ResultArray = append(res.ResultArray, i)
164+
}
165+
161166
if attempts > 1 {
162167
baseURL := fmt.Sprintf("%s://%s", r.URL.Scheme, r.Host)
163168
if r.URL.Scheme == "" { // Fallback if Scheme is not available

0 commit comments

Comments
 (0)