Skip to content

Commit

Permalink
Remove hardcoded limit for per_page in pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jun 5, 2021
1 parent 3d26366 commit 8859911
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var (
func handleGetCampaigns(c echo.Context) error {
var (
app = c.Get("app").(*App)
pg = getPagination(c.QueryParams(), 20, 50)
pg = getPagination(c.QueryParams(), 20)
out campsWrap

id, _ = strconv.Atoi(c.Param("id"))
Expand Down
11 changes: 7 additions & 4 deletions cmd/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,18 @@ func subscriberExists(next echo.HandlerFunc, params ...string) echo.HandlerFunc
}

// getPagination takes form values and extracts pagination values from it.
func getPagination(q url.Values, perPage, maxPerPage int) pagination {
page, _ := strconv.Atoi(q.Get("page"))
pp := q.Get("per_page")
func getPagination(q url.Values, perPage int) pagination {
var (
page, _ = strconv.Atoi(q.Get("page"))
pp = q.Get("per_page")
)

if pp == "all" {
// No limit.
perPage = 0
} else {
ppi, _ := strconv.Atoi(pp)
if ppi > 0 && ppi <= maxPerPage {
if ppi > 0 {
perPage = ppi
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func handleGetLists(c echo.Context) error {
app = c.Get("app").(*App)
out listsWrap

pg = getPagination(c.QueryParams(), 20, 50)
pg = getPagination(c.QueryParams(), 20)
orderBy = c.FormValue("order_by")
order = c.FormValue("order")
listID, _ = strconv.Atoi(c.Param("id"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func handleGetSubscriber(c echo.Context) error {
func handleQuerySubscribers(c echo.Context) error {
var (
app = c.Get("app").(*App)
pg = getPagination(c.QueryParams(), 30, 100)
pg = getPagination(c.QueryParams(), 30)

// Limit the subscribers to a particular list?
listID, _ = strconv.Atoi(c.FormValue("list_id"))
Expand Down

0 comments on commit 8859911

Please sign in to comment.