Skip to content

Commit 22920de

Browse files
committed
iter
1 parent 76b8698 commit 22920de

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

internal/pagination/service.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ type NonNumericCursorRequest struct {
2323
}
2424

2525
type PaginationResponse struct {
26-
<<<<<<< HEAD
27-
NumPages int `json:"numPages"`
28-
ResultArray []int `json:"resultArray"`
29-
Next *string `json:"next,omitempty"`
30-
=======
3126
NumPages int `json:"numPages"`
3227
ResultArray []interface{} `json:"resultArray"`
28+
Next *string `json:"next,omitempty"`
3329
}
3430

3531
// Insecure reversable hashing for string cursors
@@ -38,7 +34,6 @@ func hash(s string) (int, error) {
3834
}
3935
func unhash(h int) string {
4036
return strconv.Itoa(h)
41-
>>>>>>> cf9ad59 (add endpoint to support non numeric cursor.)
4237
}
4338

4439
const total = 20
@@ -151,7 +146,7 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
151146

152147
res := PaginationResponse{
153148
NumPages: 0,
154-
ResultArray: make([]int, 0),
149+
ResultArray: make([]interface{}, 0),
155150
}
156151

157152
if attempts > 1 {
@@ -184,7 +179,6 @@ func HandleNonNumericCursor(w http.ResponseWriter, r *http.Request) {
184179
if err := json.NewDecoder(r.Body).Decode(&pagination); err != nil {
185180
hasBody = false
186181
}
187-
188182
cursor := getNonNumericValue(queryCursor, hasBody, pagination.Cursor)
189183

190184
res := PaginationResponse{
@@ -219,6 +213,10 @@ func getNonNumericValue(queryValue string, hasBody bool, paginationValue string)
219213
if hasBody {
220214
return paginationValue
221215
} else {
222-
return queryValue
216+
if queryValue == "" {
217+
return "-1"
218+
} else {
219+
return queryValue
220+
}
223221
}
224222
}

0 commit comments

Comments
 (0)