From 77cab972a6c63762b10261ae659319d0e6ce7eb0 Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Wed, 14 Dec 2016 00:12:36 -0800 Subject: [PATCH] add update func to dashboards --- bolt/dashboards.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bolt/dashboards.go b/bolt/dashboards.go index 81d3b95be6..14f83b5018 100644 --- a/bolt/dashboards.go +++ b/bolt/dashboards.go @@ -96,5 +96,23 @@ func (s *DashboardsStore) Delete(ctx context.Context, d *chronograf.Dashboard) e // Update the dashboard in DashboardsStore func (s *DashboardsStore) Update(ctx context.Context, d *chronograf.Dashboard) error { + if err := s.client.db.Update(func(tx *bolt.Tx) error { + // Get an existing dashboard with the same ID. + b := tx.Bucket(DashboardBucket) + strID := strconv.Itoa(int(d.ID)) + if v := b.Get([]byte(strID)); v == nil { + return chronograf.ErrDashboardNotFound + } + + if v, err := internal.MarshalDashboard(*d); err != nil { + return err + } else if err := b.Put([]byte(strID), v); err != nil { + return err + } + return nil + }); err != nil { + return err + } + return nil }