Closed
Description
Summary
Create a generalized pagination function available for module Querier
s.
Problem Definition
Currently, there's some code redundancy for pagination logic and not all the endpoints that return batched items use pagination. The goal of this issue is to create a general pagination function and use it all across the modules' REST endpoints. This functionality should live under /types/rest/rest.go
.
Additionally, the implementer will have to update the swagger.yaml
docs and add the query parameters for pagination and limit to each of the affected endpoints.
Proposal
Idea:
func PaginateResponse(lenItems, limit, page int) (start, end int) {
if limit== 0 {
limit = lenItems
}
start = (page - 1) * limit
end = limit + start
if end >= lenItems {
end = lenItems
}
if start >= lenItems {
// page is out of bounds
return -1, -1
}
return
}
and on each of the queriers (see each module's querier.go
):
...
start, end := PaginateResponse(len(items), params.Limit, params.Page)
if start == -1 && end == -1 {
items = items{}
} else {
items = items[start:end]
}
...
For Admin Use
- Not duplicate issue
- Appropriate labels applied
- Appropriate contributors tagged
- Contributor assigned/self-assigned
Activity