Fix ExplorationID and UserID in mock
parent
eb39e5d01d
commit
5c4a602083
|
@ -103,7 +103,7 @@ func (m *Handler) Explorations(ctx context.Context, params op.GetSourcesIDUsersU
|
|||
if err != nil {
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsDefault(500)
|
||||
}
|
||||
exs, err := m.Store.Query(ctx, id)
|
||||
exs, err := m.Store.Query(ctx, mrfusion.UserID(id))
|
||||
if err != nil {
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsNotFound()
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func (m *Handler) Exploration(ctx context.Context, params op.GetSourcesIDUsersUs
|
|||
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 {
|
||||
log.Printf("Error unknown exploration id: %d: %v", eID, err)
|
||||
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)
|
||||
}
|
||||
|
||||
e, err := m.Store.Get(ctx, eID)
|
||||
e, err := m.Store.Get(ctx, mrfusion.ExplorationID(eID))
|
||||
if err != nil {
|
||||
log.Printf("Error unknown exploration id: %d: %v", eID, err)
|
||||
errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"}
|
||||
return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg)
|
||||
}
|
||||
if params.Exploration != nil {
|
||||
e.ID = eID
|
||||
e.ID = mrfusion.ExplorationID(eID)
|
||||
e.Data = params.Exploration.Data.(string)
|
||||
e.Name = params.Exploration.Name
|
||||
m.Store.Update(ctx, e)
|
||||
|
@ -188,7 +188,7 @@ func (m *Handler) NewExploration(ctx context.Context, params op.PostSourcesIDUse
|
|||
return op.NewPostSourcesIDUsersUserIDExplorationsDefault(500)
|
||||
}
|
||||
|
||||
exs, err := m.Store.Query(ctx, id)
|
||||
exs, err := m.Store.Query(ctx, mrfusion.UserID(id))
|
||||
if err != nil {
|
||||
log.Printf("Error unknown user id: %d: %v", id, err)
|
||||
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{
|
||||
Data: params.Exploration.Data.(string),
|
||||
Name: params.Exploration.Name,
|
||||
ID: eID,
|
||||
ID: mrfusion.ExplorationID(eID),
|
||||
}
|
||||
m.Store.Add(ctx, e)
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ func (m *Handler) DeleteExploration(ctx context.Context, params op.DeleteSources
|
|||
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)
|
||||
errMsg := &models.Error{Code: 404, Message: "Error unknown user id"}
|
||||
return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg)
|
||||
|
|
12
mock/mock.go
12
mock/mock.go
|
@ -36,7 +36,7 @@ func NewExplorationStore(nowFunc func() time.Time) mrfusion.ExplorationStore {
|
|||
|
||||
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{}
|
||||
for _, v := range m.db {
|
||||
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 {
|
||||
delete(m.db, e.ID)
|
||||
delete(m.db, int(e.ID))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *ExplorationStore) Get(ctx context.Context, ID int) (mrfusion.Exploration, error) {
|
||||
e, ok := m.db[ID]
|
||||
func (m *ExplorationStore) Get(ctx context.Context, ID mrfusion.ExplorationID) (mrfusion.Exploration, error) {
|
||||
e, ok := m.db[int(ID)]
|
||||
if !ok {
|
||||
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 {
|
||||
_, ok := m.db[e.ID]
|
||||
_, ok := m.db[int(e.ID)]
|
||||
if !ok {
|
||||
return fmt.Errorf("Unknown ID %d", e.ID)
|
||||
}
|
||||
e.UpdatedAt = m.NowFunc()
|
||||
m.db[e.ID] = e
|
||||
m.db[int(e.ID)] = e
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue