@@ -28,6 +28,15 @@ type PaginationResponse struct {
28
28
Next * string `json:"next,omitempty"`
29
29
}
30
30
31
+ type PageInfo struct {
32
+ NumPages int `json:"numPages"`
33
+ Next * string `json:"next,omitempty"`
34
+ }
35
+ type PaginationResponseDeep struct {
36
+ ResultArray []interface {} `json:"resultArray"`
37
+ PageInfo PageInfo `json:"pageInfo"`
38
+ }
39
+
31
40
// Insecure reversable hashing for string cursors
32
41
func hash (s string ) (int , error ) {
33
42
return strconv .Atoi (s )
@@ -197,6 +206,41 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
197
206
}
198
207
}
199
208
209
+ func HandleLimitOffsetDeepOutputsPage (w http.ResponseWriter , r * http.Request ) {
210
+ queryLimit := r .FormValue ("limit" )
211
+ queryPage := r .FormValue ("page" )
212
+
213
+ var pagination LimitOffsetRequest
214
+ hasBody := true
215
+ if err := json .NewDecoder (r .Body ).Decode (& pagination ); err != nil {
216
+ hasBody = false
217
+ }
218
+ limit := getValue (queryLimit , hasBody , pagination .Limit )
219
+ if limit == 0 {
220
+ limit = 20
221
+ }
222
+ page := getValue (queryPage , hasBody , pagination .Page )
223
+
224
+ start := (page - 1 ) * limit
225
+
226
+ res := PaginationResponseDeep {
227
+ PageInfo : PageInfo {
228
+ NumPages : int (math .Ceil (float64 (total ) / float64 (limit ))),
229
+ },
230
+ ResultArray : make ([]interface {}, 0 ),
231
+ }
232
+
233
+ for i := start ; i < total && len (res .ResultArray ) < limit ; i ++ {
234
+ res .ResultArray = append (res .ResultArray , i )
235
+ }
236
+
237
+ w .Header ().Set ("Content-Type" , "application/json" )
238
+ err := json .NewEncoder (w ).Encode (res )
239
+ if err != nil {
240
+ w .WriteHeader (500 )
241
+ }
242
+ }
243
+
200
244
func getValue (queryValue string , hasBody bool , paginationValue int ) int {
201
245
if hasBody {
202
246
return paginationValue
0 commit comments