Fix ExplorationID and UserID in mock

pull/10616/head
gunnaraasen 2016-09-28 10:57:15 -04:00
parent eb39e5d01d
commit 5c4a602083
2 changed files with 13 additions and 13 deletions

View File

@ -103,7 +103,7 @@ func (m *Handler) Explorations(ctx context.Context, params op.GetSourcesIDUsersU
if err != nil { if err != nil {
return op.NewGetSourcesIDUsersUserIDExplorationsDefault(500) return op.NewGetSourcesIDUsersUserIDExplorationsDefault(500)
} }
exs, err := m.Store.Query(ctx, id) exs, err := m.Store.Query(ctx, mrfusion.UserID(id))
if err != nil { if err != nil {
return op.NewGetSourcesIDUsersUserIDExplorationsNotFound() return op.NewGetSourcesIDUsersUserIDExplorationsNotFound()
} }
@ -139,7 +139,7 @@ func (m *Handler) Exploration(ctx context.Context, params op.GetSourcesIDUsersUs
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDDefault(500).WithPayload(errMsg) return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDDefault(500).WithPayload(errMsg)
} }
e, err := m.Store.Get(ctx, eID) e, err := m.Store.Get(ctx, mrfusion.ExplorationID(eID))
if err != nil { if err != nil {
log.Printf("Error unknown exploration id: %d: %v", eID, err) log.Printf("Error unknown exploration id: %d: %v", eID, err)
errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"} errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"}
@ -167,14 +167,14 @@ func (m *Handler) UpdateExploration(ctx context.Context, params op.PatchSourcesI
return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDDefault(500) return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDDefault(500)
} }
e, err := m.Store.Get(ctx, eID) e, err := m.Store.Get(ctx, mrfusion.ExplorationID(eID))
if err != nil { if err != nil {
log.Printf("Error unknown exploration id: %d: %v", eID, err) log.Printf("Error unknown exploration id: %d: %v", eID, err)
errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"} errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"}
return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg) return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg)
} }
if params.Exploration != nil { if params.Exploration != nil {
e.ID = eID e.ID = mrfusion.ExplorationID(eID)
e.Data = params.Exploration.Data.(string) e.Data = params.Exploration.Data.(string)
e.Name = params.Exploration.Name e.Name = params.Exploration.Name
m.Store.Update(ctx, e) m.Store.Update(ctx, e)
@ -188,7 +188,7 @@ func (m *Handler) NewExploration(ctx context.Context, params op.PostSourcesIDUse
return op.NewPostSourcesIDUsersUserIDExplorationsDefault(500) return op.NewPostSourcesIDUsersUserIDExplorationsDefault(500)
} }
exs, err := m.Store.Query(ctx, id) exs, err := m.Store.Query(ctx, mrfusion.UserID(id))
if err != nil { if err != nil {
log.Printf("Error unknown user id: %d: %v", id, err) log.Printf("Error unknown user id: %d: %v", id, err)
errMsg := &models.Error{Code: 404, Message: "Error unknown user id"} errMsg := &models.Error{Code: 404, Message: "Error unknown user id"}
@ -200,7 +200,7 @@ func (m *Handler) NewExploration(ctx context.Context, params op.PostSourcesIDUse
e := mrfusion.Exploration{ e := mrfusion.Exploration{
Data: params.Exploration.Data.(string), Data: params.Exploration.Data.(string),
Name: params.Exploration.Name, Name: params.Exploration.Name,
ID: eID, ID: mrfusion.ExplorationID(eID),
} }
m.Store.Add(ctx, e) m.Store.Add(ctx, e)
} }
@ -225,7 +225,7 @@ func (m *Handler) DeleteExploration(ctx context.Context, params op.DeleteSources
return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDDefault(500) return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDDefault(500)
} }
if err := m.Store.Delete(ctx, mrfusion.Exploration{ID: ID}); err != nil { if err := m.Store.Delete(ctx, mrfusion.Exploration{ID: mrfusion.ExplorationID(ID)}); err != nil {
log.Printf("Error unknown explorations id: %d: %v", ID, err) log.Printf("Error unknown explorations id: %d: %v", ID, err)
errMsg := &models.Error{Code: 404, Message: "Error unknown user id"} errMsg := &models.Error{Code: 404, Message: "Error unknown user id"}
return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg) return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg)

View File

@ -36,7 +36,7 @@ func NewExplorationStore(nowFunc func() time.Time) mrfusion.ExplorationStore {
var DefaultExplorationStore mrfusion.ExplorationStore = NewExplorationStore(time.Now) var DefaultExplorationStore mrfusion.ExplorationStore = NewExplorationStore(time.Now)
func (m *ExplorationStore) Query(ctx context.Context, userID int) ([]mrfusion.Exploration, error) { func (m *ExplorationStore) Query(ctx context.Context, userID mrfusion.UserID) ([]mrfusion.Exploration, error) {
res := []mrfusion.Exploration{} res := []mrfusion.Exploration{}
for _, v := range m.db { for _, v := range m.db {
res = append(res, v) res = append(res, v)
@ -52,12 +52,12 @@ func (m *ExplorationStore) Add(ctx context.Context, e mrfusion.Exploration) erro
} }
func (m *ExplorationStore) Delete(ctx context.Context, e mrfusion.Exploration) error { func (m *ExplorationStore) Delete(ctx context.Context, e mrfusion.Exploration) error {
delete(m.db, e.ID) delete(m.db, int(e.ID))
return nil return nil
} }
func (m *ExplorationStore) Get(ctx context.Context, ID int) (mrfusion.Exploration, error) { func (m *ExplorationStore) Get(ctx context.Context, ID mrfusion.ExplorationID) (mrfusion.Exploration, error) {
e, ok := m.db[ID] e, ok := m.db[int(ID)]
if !ok { if !ok {
return mrfusion.Exploration{}, fmt.Errorf("Unknown ID %d", ID) return mrfusion.Exploration{}, fmt.Errorf("Unknown ID %d", ID)
} }
@ -65,12 +65,12 @@ func (m *ExplorationStore) Get(ctx context.Context, ID int) (mrfusion.Exploratio
} }
func (m *ExplorationStore) Update(ctx context.Context, e mrfusion.Exploration) error { func (m *ExplorationStore) Update(ctx context.Context, e mrfusion.Exploration) error {
_, ok := m.db[e.ID] _, ok := m.db[int(e.ID)]
if !ok { if !ok {
return fmt.Errorf("Unknown ID %d", e.ID) return fmt.Errorf("Unknown ID %d", e.ID)
} }
e.UpdatedAt = m.NowFunc() e.UpdatedAt = m.NowFunc()
m.db[e.ID] = e m.db[int(e.ID)] = e
return nil return nil
} }