feat(http): add ids param to dashboard endpoint

pull/10616/head
Jade McGough 2018-10-04 16:30:51 -07:00
parent 770a9de282
commit ce849bb39e
3 changed files with 42 additions and 12 deletions

View File

@ -62,9 +62,7 @@ type Cell struct {
// DashboardFilter is a filter for dashboards.
type DashboardFilter struct {
// TODO(desa): change to be a slice of IDs
ID *ID
OwnerID *ID
IDs []*ID
}
// DashboardUpdate is the patch structure for a dashboard.

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"net/http"
"path"
"strings"
"github.com/influxdata/platform"
"github.com/influxdata/platform/kit/errors"
@ -161,6 +162,22 @@ func (h *DashboardHandler) handleGetDashboards(w http.ResponseWriter, r *http.Re
return
}
// if req.filter.OwnerID != nil {
// filter := platform.UserResourceMappingFilter{
// UserID: req.filter.OwnerID,
// UserType: platform.Owner,
// }
//
// mappings, _, err := h.UserResourceMappingService.FindUserResourceMappings(ctx, filter)
// if err != nil {
// EncodeError(ctx, errors.InternalErrorf("Error loading dashboard owners: %v", err), w)
// return
// }
//
// // filter out dashboards by mapping; O(m*n)
// // can also make a hash to compare to
// }
if err := encodeResponse(ctx, w, http.StatusOK, newGetDashboardsResponse(dashboards)); err != nil {
EncodeError(ctx, err, w)
return
@ -169,22 +186,27 @@ func (h *DashboardHandler) handleGetDashboards(w http.ResponseWriter, r *http.Re
type getDashboardsRequest struct {
filter platform.DashboardFilter
ownerID *platform.ID
}
func decodeGetDashboardsRequest(ctx context.Context, r *http.Request) (*getDashboardsRequest, error) {
qp := r.URL.Query()
req := &getDashboardsRequest{}
if id := qp.Get("id"); id != "" {
req.filter.ID = &platform.ID{}
if err := req.filter.ID.DecodeFromString(id); err != nil {
if idsStr := qp.Get("ids"); idsStr != "" {
ids := strings.Split(idsStr, ",")
for _, id := range ids {
i := &platform.ID{}
if err := i.DecodeFromString(id); err != nil {
return nil, err
}
req.filter.IDs = append(req.filter.IDs, i)
}
}
if owner := qp.Get("owner"); owner != "" {
req.filter.OwnerID = &platform.ID{}
if err := req.filter.OwnerID.DecodeFromString(owner); err != nil {
req.ownerID = &platform.ID{}
if err := req.ownerID.DecodeFromString(owner); err != nil {
return nil, err
}
}
@ -670,8 +692,12 @@ func (s *DashboardService) FindDashboards(ctx context.Context, filter platform.D
}
qp := url.Query()
if filter.ID != nil {
qp.Add("id", filter.ID.String())
if len(filter.IDs) > 0 {
var ids string
for _, id := range filter.IDs {
ids = ids + id.String()
}
qp.Add("id", ids)
}
url.RawQuery = qp.Encode()

View File

@ -731,6 +731,12 @@ paths:
description: specifies the owner to return resources for
schema:
type: string
- in: query
name: ids
description: a comma separated list of ids to return
schema:
type: string
example: 273de20b5b,667d679f84
responses:
'200':
description: all dashboards