Remove hardcoded limit for per_page in pagination

This commit is contained in:
Kailash Nadh 2021-06-05 12:01:33 +05:30
parent 3d26366620
commit 8859911c73
4 changed files with 10 additions and 7 deletions

View file

@ -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"))

View file

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

View file

@ -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"))

View file

@ -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"))