From aecae32b4ae6b73b9945cdedef5a5b0dafa11973 Mon Sep 17 00:00:00 2001 From: Dan Ramich Date: Thu, 21 Jun 2018 11:20:19 -0700 Subject: [PATCH] Fix pagination Problem: Pagination is not showing up Solution: Pagination was being created properly but then dropped in favor of an empty version. Save the pagination on the context so it can be accessed later and not reset. --- api/handler/list.go | 2 ++ parse/collection.go | 4 ++++ types/server_types.go | 1 + 3 files changed, 7 insertions(+) diff --git a/api/handler/list.go b/api/handler/list.go index 066944278..9b9fb0522 100644 --- a/api/handler/list.go +++ b/api/handler/list.go @@ -21,6 +21,8 @@ func ListHandler(request *types.APIContext, next types.RequestHandler) error { if request.ID == "" { opts := parse.QueryOptions(request, request.Schema) + // Save the pagination on the context so it's not reset later + request.Pagination = opts.Pagination data, err = store.List(request, request.Schema, &opts) } else if request.Link == "" { data, err = store.ByID(request, request.Schema, request.ID) diff --git a/parse/collection.go b/parse/collection.go index 1cbf0c3df..f6a20afc8 100644 --- a/parse/collection.go +++ b/parse/collection.go @@ -48,6 +48,10 @@ func parseSort(schema *types.Schema, apiContext *types.APIContext) types.Sort { } func parsePagination(apiContext *types.APIContext) *types.Pagination { + if apiContext.Pagination != nil { + return apiContext.Pagination + } + q := apiContext.Query limit := q.Get("limit") marker := q.Get("marker") diff --git a/types/server_types.go b/types/server_types.go index 3b11ead77..654a86bb6 100644 --- a/types/server_types.go +++ b/types/server_types.go @@ -101,6 +101,7 @@ type APIContext struct { URLBuilder URLBuilder AccessControl AccessControl SubContext map[string]string + Pagination *Pagination Request *http.Request Response http.ResponseWriter