From 16b79cebec84209b8851acc81d735d55fa76be0f Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Thu, 29 Sep 2016 10:24:54 -0400 Subject: [PATCH] Update exploration store interface to return exploration on add --- bolt/exploration.go | 6 +++--- bolt/exploration_test.go | 4 ++-- mock/mock.go | 4 ++-- stores.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bolt/exploration.go b/bolt/exploration.go index 3e0f04898f..dd02529384 100644 --- a/bolt/exploration.go +++ b/bolt/exploration.go @@ -41,7 +41,7 @@ func (s *ExplorationStore) Query(ctx context.Context, uid mrfusion.UserID) ([]*m } // Create a new Exploration in the ExplorationStore. -func (s *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) error { +func (s *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) (*mrfusion.Exploration, error) { if err := s.client.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(ExplorationBucket) seq, err := b.NextSequence() @@ -58,10 +58,10 @@ func (s *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) err } return nil }); err != nil { - return err + return nil, err } - return nil + return e, nil } // Delete the exploration from the ExplorationStore diff --git a/bolt/exploration_test.go b/bolt/exploration_test.go index e700902909..01cdaaba22 100644 --- a/bolt/exploration_test.go +++ b/bolt/exploration_test.go @@ -74,7 +74,7 @@ func TestExplorationStore_CRUD(t *testing.T) { // Add new explorations. for i := range explorations { - if err := s.Add(nil, explorations[i]); err != nil { + if _, err := s.Add(nil, explorations[i]); err != nil { t.Fatal(err) } } @@ -156,7 +156,7 @@ func TestExplorationStore_Query(t *testing.T) { // Add new explorations. for i := range explorations { - if err := s.Add(nil, explorations[i]); err != nil { + if _, err := s.Add(nil, explorations[i]); err != nil { t.Fatal(err) } } diff --git a/mock/mock.go b/mock/mock.go index 5a2c852b6d..37bf4424f9 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -44,11 +44,11 @@ func (m *ExplorationStore) Query(ctx context.Context, userID mrfusion.UserID) ([ return res, nil } -func (m *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) error { +func (m *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) (*mrfusion.Exploration, error) { e.CreatedAt = m.NowFunc() e.UpdatedAt = m.NowFunc() m.db[len(m.db)] = e - return nil + return e, nil } func (m *ExplorationStore) Delete(ctx context.Context, e *mrfusion.Exploration) error { diff --git a/stores.go b/stores.go index 548ae01ae8..f68d45ecd3 100644 --- a/stores.go +++ b/stores.go @@ -79,7 +79,7 @@ type ExplorationStore interface { // Search the ExplorationStore for each Exploration owned by `UserID`. Query(ctx context.Context, userID UserID) ([]*Exploration, error) // Create a new Exploration in the ExplorationStore. - Add(context.Context, *Exploration) error + Add(context.Context, *Exploration) (*Exploration, error) // Delete the Exploration from the ExplorationStore. Delete(context.Context, *Exploration) error // Retrieve an Exploration if `ID` exists.