fix: pagination queries

- refactor keyset pagination query to correctly fecth previous page
- remove pagination from token list
- add fetch latest transactions by token
This commit is contained in:
2022-06-16 12:21:58 +03:00
parent 6f7c6d9718
commit fe0e102a61
6 changed files with 163 additions and 39 deletions

View File

@@ -6,29 +6,32 @@ import (
)
type Pagination struct {
PerPage int
Cursor int
Forward bool
PerPage int
Cursor int
Next bool
FirstPage bool
}
func GetPagination(q url.Values) Pagination {
var (
pp, _ = strconv.Atoi(q.Get("per_page"))
cursor, _ = strconv.Atoi(q.Get("cursor"))
forward, _ = strconv.ParseBool(q.Get("forward"))
pp, _ = strconv.Atoi(q.Get("per_page"))
cursor, _ = strconv.Atoi(q.Get("cursor"))
next, _ = strconv.ParseBool(q.Get("next"))
firstPage = false
)
if pp > 100 {
pp = 100
}
if !forward && cursor < 1 {
cursor = 1
if !next && cursor < 1 {
firstPage = true
}
return Pagination{
PerPage: pp,
Cursor: cursor,
Forward: forward,
PerPage: pp,
Cursor: cursor,
Next: next,
FirstPage: firstPage,
}
}