feat(http): dashboards protos pagination

pull/11203/head
Leonardo Di Donato 2019-01-16 17:56:28 +01:00 committed by Leo Di Donato
parent 70921b6014
commit e8ecc6a712
2 changed files with 9 additions and 2 deletions

View File

@ -122,6 +122,7 @@ func (h *ProtoHandler) handleGetProtos(w http.ResponseWriter, r *http.Request) {
type createProtoResourcesRequest struct {
ProtoID platform.ID `json:"-"`
OrganizationID platform.ID `json:"orgID"`
opts platform.FindOptions
}
// Decode turns an http request into a createProtoResourceRequest.
@ -132,6 +133,12 @@ func (r *createProtoResourcesRequest) Decode(req *http.Request) error {
return err
}
opts, err := decodeFindOptions(ctx, req)
if err != nil {
return err
}
r.opts = *opts
r.ProtoID = id
if err := json.NewDecoder(req.Body).Decode(r); err != nil {
@ -157,7 +164,7 @@ func (h *ProtoHandler) handlePostProtosDashboards(w http.ResponseWriter, r *http
}
filter := platform.DashboardFilter{OrganizationID: &req.OrganizationID}
if err := encodeResponse(ctx, w, http.StatusCreated, newGetDashboardsResponse(ctx, ds, filter, h.LabelService)); err != nil {
if err := encodeResponse(ctx, w, http.StatusCreated, newGetDashboardsResponse(ctx, ds, filter, req.opts, h.LabelService)); err != nil {
logEncodingError(h.Logger, r, err)
return
}

View File

@ -197,7 +197,7 @@ func TestProtoHandler(t *testing.T) {
}
],
"links": {
"self": "/api/v2/dashboards?orgID=0000000000000001"
"self": "/api/v2/dashboards?descending=false&limit=20&offset=0&orgID=0000000000000001"
}
}
`,