@@ -123,21 +123,62 @@ func HandleCursor(w http.ResponseWriter, r *http.Request) {
123
123
}
124
124
125
125
cursor := getValue (queryCursor , hasBody , pagination .Cursor )
126
+ resultArray := make ([]interface {}, 0 )
126
127
128
+ for i := cursor + 1 ; i < total && len (resultArray ) < 15 ; i ++ {
129
+ resultArray = append (resultArray , i )
130
+ }
131
+
132
+ w .Header ().Set ("Content-Type" , "application/json" )
127
133
res := PaginationResponse {
128
134
NumPages : 0 ,
129
- ResultArray : make ([] interface {}, 0 ) ,
135
+ ResultArray : resultArray ,
130
136
}
131
137
132
- for i := cursor + 1 ; i < total && len (res .ResultArray ) < 15 ; i ++ {
133
- res .ResultArray = append (res .ResultArray , i )
138
+ err := json .NewEncoder (w ).Encode (res )
139
+ if err != nil {
140
+ w .WriteHeader (500 )
141
+ }
142
+
143
+ }
144
+
145
+ func HandleCursorResponseEnvelope (w http.ResponseWriter , r * http.Request ) {
146
+ queryCursor := r .FormValue ("cursor" )
147
+
148
+ var pagination CursorRequest
149
+ hasBody := true
150
+ if err := json .NewDecoder (r .Body ).Decode (& pagination ); err != nil {
151
+ hasBody = false
152
+ }
153
+
154
+ cursor := getValue (queryCursor , hasBody , pagination .Cursor )
155
+ resultArray := make ([]interface {}, 0 )
156
+
157
+ for i := cursor + 1 ; i < total && len (resultArray ) < 15 ; i ++ {
158
+ resultArray = append (resultArray , i )
134
159
}
135
160
136
161
w .Header ().Set ("Content-Type" , "application/json" )
162
+ var lastItem * string
163
+ if len (resultArray ) > 0 {
164
+ idx := strconv .Itoa (resultArray [len (resultArray )- 1 ].(int ))
165
+ lastItem = & idx
166
+ } else {
167
+ lastItem = nil
168
+ }
169
+
170
+ res := PaginationResponseDeep {
171
+ PageInfo : PageInfo {
172
+ Next : lastItem ,
173
+ },
174
+ ResultArray : resultArray ,
175
+ }
176
+
137
177
err := json .NewEncoder (w ).Encode (res )
138
178
if err != nil {
139
179
w .WriteHeader (500 )
140
180
}
181
+
141
182
}
142
183
143
184
func HandleURL (w http.ResponseWriter , r * http.Request ) {
0 commit comments