add dashboard GET and DELETE handlers
parent
43464f6008
commit
7986ecce3f
|
@ -52,9 +52,28 @@ func (s *Service) Dashboards(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// DashboardID returns a single specified dashboard
|
// DashboardID returns a single specified dashboard
|
||||||
func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id, err := paramID("id", r)
|
||||||
|
if err != nil {
|
||||||
|
Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
|
e, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
|
||||||
|
if err != nil {
|
||||||
|
notFound(w, id, s.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res := newDashboardResponse(e)
|
||||||
|
encodeJSON(w, http.StatusOK, res, s.Logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// type postDashboardRequest struct {
|
||||||
|
// Data interface{} `json:"data"` // Serialization of config.
|
||||||
|
// Name string `json:"name,omitempty"` // Exploration name given by user.
|
||||||
|
// }
|
||||||
|
|
||||||
// NewDashboard creates and returns a new dashboard object
|
// NewDashboard creates and returns a new dashboard object
|
||||||
func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
@ -62,7 +81,24 @@ func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// RemoveDashboard deletes a dashboard
|
// RemoveDashboard deletes a dashboard
|
||||||
func (s *Service) RemoveDashboard(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) RemoveDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id, err := paramID("id", r)
|
||||||
|
if err != nil {
|
||||||
|
Error(w, http.StatusUnprocessableEntity, err.Error(), h.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
|
e, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
|
||||||
|
if err != nil {
|
||||||
|
notFound(w, id, s.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.DashboardsStore.Delete(ctx, &chronograf.Dashboard{ID: chronograf.DashboardID(id)}); err != nil {
|
||||||
|
unknownErrorWithMessage(w, err, s.Logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateDashboard updates a dashboard
|
// UpdateDashboard updates a dashboard
|
||||||
|
|
Loading…
Reference in New Issue