mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-11-14 03:46:46 +01:00
Mohamed Sohail
b59c0ba3fc
* sql: add transaction transaction record queries - get full tx history - get latest txs for a specific token * sql: (fix) add id column to select * sql: (fix) change column name to identifier * fix: pagination queries - refactor keyset pagination query to correctly fecth previous page - remove pagination from token list - add fetch latest transactions by token * tidy: remove dev logs * feat: (db) add index for desc for pagination
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,
|
|
}
|
|
}
|