Skip to content

Commit

Permalink
chore: Update URL pagination endpoint to return results
Browse files Browse the repository at this point in the history
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":[]}
```
  • Loading branch information
bflad authored Jul 22, 2024
2 parents 135c690 + 21ac6ca commit bf8ac67
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/pagination/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
ResultArray: make([]interface{}, 0),
}

// 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)
}

if attempts > 1 {
baseURL := fmt.Sprintf("%s://%s", r.URL.Scheme, r.Host)
if r.URL.Scheme == "" { // Fallback if Scheme is not available
Expand Down

0 comments on commit bf8ac67

Please sign in to comment.