cic-dw/pkg/pagination/pagination.go
Mohamed Sohail b59c0ba3fc
feat: transaction history (including by voucher) (#24)
* 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
2022-06-16 12:27:18 +03:00

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,
}
}