mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2025-02-01 18:37:31 +01:00
Mohammed Sohail
fe0e102a61
- refactor keyset pagination query to correctly fecth previous page - remove pagination from token list - add fetch latest transactions by token
38 lines
543 B
Go
38 lines
543 B
Go
package pagination
|
|
|
|
import (
|
|
"net/url"
|
|
"strconv"
|
|
)
|
|
|
|
type Pagination struct {
|
|
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"))
|
|
next, _ = strconv.ParseBool(q.Get("next"))
|
|
firstPage = false
|
|
)
|
|
|
|
if pp > 100 {
|
|
pp = 100
|
|
}
|
|
|
|
if !next && cursor < 1 {
|
|
firstPage = true
|
|
}
|
|
|
|
return Pagination{
|
|
PerPage: pp,
|
|
Cursor: cursor,
|
|
Next: next,
|
|
FirstPage: firstPage,
|
|
}
|
|
}
|