1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 06:35:09 +00:00
Files
norman/api/handler/list.go

44 lines
978 B
Go
Raw Normal View History

2017-11-21 13:46:30 -07:00
package handler
2017-11-10 21:44:02 -07:00
import (
"net/http"
"github.com/rancher/norman/httperror"
2017-11-10 21:44:02 -07:00
"github.com/rancher/norman/parse"
"github.com/rancher/norman/types"
)
2018-01-30 16:49:37 -07:00
func ListHandler(request *types.APIContext, next types.RequestHandler) error {
2017-11-10 21:44:02 -07:00
var (
err error
data interface{}
)
store := request.Schema.Store
if store == nil {
return httperror.NewAPIError(httperror.NotFound, "no store found")
2017-11-10 21:44:02 -07:00
}
if request.ID == "" {
2017-11-21 13:46:30 -07:00
opts := parse.QueryOptions(request, request.Schema)
// Save the pagination on the context so it's not reset later
request.Pagination = opts.Pagination
2017-12-28 08:47:10 -07:00
data, err = store.List(request, request.Schema, &opts)
2017-11-10 21:44:02 -07:00
} else if request.Link == "" {
data, err = store.ByID(request, request.Schema, request.ID)
} else {
2018-03-22 15:53:36 -07:00
_, err = store.ByID(request, request.Schema, request.ID)
if err != nil {
return err
}
2018-01-30 16:49:37 -07:00
return request.Schema.LinkHandler(request, nil)
2017-11-10 21:44:02 -07:00
}
if err != nil {
return err
}
request.WriteResponse(http.StatusOK, data)
return nil
}