1
0
mirror of https://github.com/rancher/norman.git synced 2025-06-20 04:31:54 +00:00
norman/api/handler/list.go
Dan Ramich aecae32b4a 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.
2018-06-25 15:34:52 -07:00

44 lines
978 B
Go

package handler
import (
"net/http"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/parse"
"github.com/rancher/norman/types"
)
func ListHandler(request *types.APIContext, next types.RequestHandler) error {
var (
err error
data interface{}
)
store := request.Schema.Store
if store == nil {
return httperror.NewAPIError(httperror.NotFound, "no store found")
}
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)
} else {
_, err = store.ByID(request, request.Schema, request.ID)
if err != nil {
return err
}
return request.Schema.LinkHandler(request, nil)
}
if err != nil {
return err
}
request.WriteResponse(http.StatusOK, data)
return nil
}