Skip to content

Commit b7bf47c

Browse files
GorshkovIvanIvan Gorshkov
andauthored
fix: Add empty string cursor support for pagination endpoint (#33)
* adding empty string for cursor pagination endpoint * cleaned up cursor logic * refactoring --------- Co-authored-by: Ivan Gorshkov <[email protected]>
1 parent f9fc787 commit b7bf47c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/pagination/service.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
229229
}
230230

231231
func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
232+
vals, ok := r.URL.Query()["endCursor"]
233+
var endCursor *string
234+
if ok && len(vals) > 0 {
235+
endCursor = &vals[0]
236+
}
237+
232238
limit := 15
233239

234240
queryCursor := r.FormValue("cursor")
@@ -249,10 +255,11 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
249255
res.ResultArray = append(res.ResultArray, unhash(i))
250256
}
251257

252-
// output cursor to $.cursor in addition to $.resultArray[(@.length-1)]
253258
if len(res.ResultArray) == limit {
254259
cursor, _ := res.ResultArray[len(res.ResultArray)-1].(string)
255260
res.Cursor = &cursor
261+
} else if endCursor != nil {
262+
res.Cursor = endCursor
256263
}
257264

258265
w.Header().Set("Content-Type", "application/json")
@@ -262,6 +269,7 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
262269
}
263270
}
264271

272+
265273
func HandleLimitOffsetDeepOutputsPage(w http.ResponseWriter, r *http.Request) {
266274
queryLimit := r.FormValue("limit")
267275
queryPage := r.FormValue("page")

0 commit comments

Comments
 (0)