Update exploration store interface to return exploration on add

pull/10616/head
gunnaraasen 2016-09-29 10:24:54 -04:00
parent e45dbdc630
commit 16b79cebec
4 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,7 @@ func (s *ExplorationStore) Query(ctx context.Context, uid mrfusion.UserID) ([]*m
} }
// Create a new Exploration in the ExplorationStore. // 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 { if err := s.client.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(ExplorationBucket) b := tx.Bucket(ExplorationBucket)
seq, err := b.NextSequence() seq, err := b.NextSequence()
@ -58,10 +58,10 @@ func (s *ExplorationStore) Add(ctx context.Context, e *mrfusion.Exploration) err
} }
return nil return nil
}); err != nil { }); err != nil {
return err return nil, err
} }
return nil return e, nil
} }
// Delete the exploration from the ExplorationStore // Delete the exploration from the ExplorationStore

View File

@ -74,7 +74,7 @@ func TestExplorationStore_CRUD(t *testing.T) {
// Add new explorations. // Add new explorations.
for i := range 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) t.Fatal(err)
} }
} }
@ -156,7 +156,7 @@ func TestExplorationStore_Query(t *testing.T) {
// Add new explorations. // Add new explorations.
for i := range 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) t.Fatal(err)
} }
} }

View File

@ -44,11 +44,11 @@ func (m *ExplorationStore) Query(ctx context.Context, userID mrfusion.UserID) ([
return res, nil 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.CreatedAt = m.NowFunc()
e.UpdatedAt = m.NowFunc() e.UpdatedAt = m.NowFunc()
m.db[len(m.db)] = e m.db[len(m.db)] = e
return nil return e, nil
} }
func (m *ExplorationStore) Delete(ctx context.Context, e *mrfusion.Exploration) error { func (m *ExplorationStore) Delete(ctx context.Context, e *mrfusion.Exploration) error {

View File

@ -79,7 +79,7 @@ type ExplorationStore interface {
// Search the ExplorationStore for each Exploration owned by `UserID`. // Search the ExplorationStore for each Exploration owned by `UserID`.
Query(ctx context.Context, userID UserID) ([]*Exploration, error) Query(ctx context.Context, userID UserID) ([]*Exploration, error)
// Create a new Exploration in the ExplorationStore. // 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 the Exploration from the ExplorationStore.
Delete(context.Context, *Exploration) error Delete(context.Context, *Exploration) error
// Retrieve an Exploration if `ID` exists. // Retrieve an Exploration if `ID` exists.