Merge pull request #124 from influxdata/feature/explorations-handlers
Add mock explorations handlers to server.pull/10616/head
commit
19330aab66
|
@ -1,7 +1,10 @@
|
|||
package mock
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
@ -105,9 +108,9 @@ func (m *Handler) Explorations(ctx context.Context, params op.GetSourcesIDUsersU
|
|||
return op.NewGetSourcesIDUsersUserIDExplorationsNotFound()
|
||||
}
|
||||
res := &models.Explorations{}
|
||||
for _, e := range exs {
|
||||
for i, e := range exs {
|
||||
rel := "self"
|
||||
href := "/chronograf/v1/source/1/users/1/explorations/1"
|
||||
href := fmt.Sprintf("/chronograf/v1/sources/1/users/%d/explorations/%d", id, i)
|
||||
res.Explorations = append(res.Explorations, &models.Exploration{
|
||||
Data: e.Data,
|
||||
Name: e.Name,
|
||||
|
@ -124,20 +127,36 @@ func (m *Handler) Explorations(ctx context.Context, params op.GetSourcesIDUsersU
|
|||
}
|
||||
|
||||
func (m *Handler) Exploration(ctx context.Context, params op.GetSourcesIDUsersUserIDExplorationsExplorationIDParams) middleware.Responder {
|
||||
id, err := strconv.Atoi(params.UserID)
|
||||
if err != nil {
|
||||
errMsg := &models.Error{Code: 500, Message: "Error converting user id"}
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsDefault(500).WithPayload(errMsg)
|
||||
}
|
||||
|
||||
eID, err := strconv.Atoi(params.ExplorationID)
|
||||
if err != nil {
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDDefault(500)
|
||||
errMsg := &models.Error{Code: 500, Message: "Error converting exploration id"}
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDDefault(500).WithPayload(errMsg)
|
||||
}
|
||||
|
||||
e, err := m.Store.Get(ctx, eID)
|
||||
if err != nil {
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDNotFound()
|
||||
log.Printf("Error unknown exploration id: %d: %v", eID, err)
|
||||
errMsg := &models.Error{Code: 404, Message: "Error unknown exploration id"}
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDNotFound().WithPayload(errMsg)
|
||||
}
|
||||
|
||||
rel := "self"
|
||||
href := fmt.Sprintf("/chronograf/v1/sources/1/users/%d/explorations/%d", id, eID)
|
||||
res := &models.Exploration{
|
||||
Data: e.Data,
|
||||
Name: e.Name,
|
||||
UpdatedAt: strfmt.DateTime(e.UpdatedAt),
|
||||
CreatedAt: strfmt.DateTime(e.CreatedAt),
|
||||
Link: &models.Link{
|
||||
Rel: &rel,
|
||||
Href: &href,
|
||||
},
|
||||
}
|
||||
return op.NewGetSourcesIDUsersUserIDExplorationsExplorationIDOK().WithPayload(res)
|
||||
}
|
||||
|
@ -150,9 +169,12 @@ func (m *Handler) UpdateExploration(ctx context.Context, params op.PatchSourcesI
|
|||
|
||||
e, err := m.Store.Get(ctx, eID)
|
||||
if err != nil {
|
||||
return op.NewPatchSourcesIDUsersUserIDExplorationsExplorationIDNotFound()
|
||||
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.Data = params.Exploration.Data.(string)
|
||||
e.Name = params.Exploration.Name
|
||||
m.Store.Update(ctx, e)
|
||||
|
@ -168,7 +190,9 @@ func (m *Handler) NewExploration(ctx context.Context, params op.PostSourcesIDUse
|
|||
|
||||
exs, err := m.Store.Query(ctx, id)
|
||||
if err != nil {
|
||||
return op.NewPostSourcesIDUsersUserIDExplorationsNotFound()
|
||||
log.Printf("Error unknown user id: %d: %v", id, err)
|
||||
errMsg := &models.Error{Code: 404, Message: "Error unknown user id"}
|
||||
return op.NewPostSourcesIDUsersUserIDExplorationsNotFound().WithPayload(errMsg)
|
||||
}
|
||||
eID := len(exs)
|
||||
|
||||
|
@ -180,7 +204,19 @@ func (m *Handler) NewExploration(ctx context.Context, params op.PostSourcesIDUse
|
|||
}
|
||||
m.Store.Add(ctx, e)
|
||||
}
|
||||
return op.NewPostSourcesIDUsersUserIDExplorationsCreated()
|
||||
params.Exploration.UpdatedAt = strfmt.DateTime(time.Now())
|
||||
params.Exploration.CreatedAt = strfmt.DateTime(time.Now())
|
||||
|
||||
loc := fmt.Sprintf("/chronograf/v1/sources/1/users/%d/explorations/%d", id, eID)
|
||||
rel := "self"
|
||||
|
||||
link := &models.Link{
|
||||
Href: &loc,
|
||||
Rel: &rel,
|
||||
}
|
||||
params.Exploration.Link = link
|
||||
return op.NewPostSourcesIDUsersUserIDExplorationsCreated().WithPayload(params.Exploration).WithLocation(loc)
|
||||
|
||||
}
|
||||
|
||||
func (m *Handler) DeleteExploration(ctx context.Context, params op.DeleteSourcesIDUsersUserIDExplorationsExplorationIDParams) middleware.Responder {
|
||||
|
@ -190,7 +226,9 @@ func (m *Handler) DeleteExploration(ctx context.Context, params op.DeleteSources
|
|||
}
|
||||
|
||||
if err := m.Store.Delete(ctx, mrfusion.Exploration{ID: ID}); err != nil {
|
||||
return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDNotFound()
|
||||
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)
|
||||
}
|
||||
return op.NewDeleteSourcesIDUsersUserIDExplorationsExplorationIDNoContent()
|
||||
}
|
||||
|
|
|
@ -18,12 +18,19 @@ func NewExplorationStore(nowFunc func() time.Time) mrfusion.ExplorationStore {
|
|||
NowFunc: nowFunc,
|
||||
db: map[int]mrfusion.Exploration{},
|
||||
}
|
||||
e.db[0] = mrfusion.Exploration{
|
||||
Name: "Ferdinand Magellan",
|
||||
Data: "{\"panels\":{\"123\":{\"id\":\"123\",\"queryIds\":[\"456\"]}},\"queryConfigs\":{\"456\":{\"id\":\"456\",\"database\":null,\"measurement\":null,\"retentionPolicy\":null,\"fields\":[],\"tags\":{},\"groupBy\":{\"time\":null,\"tags\":[]},\"areTagsAccepted\":true,\"rawText\":null}}}",
|
||||
CreatedAt: nowFunc(),
|
||||
UpdatedAt: nowFunc(),
|
||||
}
|
||||
e.db[1] = mrfusion.Exploration{
|
||||
Name: "Ferdinand Magellan",
|
||||
Data: "{\"panels\":{\"123\":{\"id\":\"123\",\"queryIds\":[\"456\"]}},\"queryConfigs\":{\"456\":{\"id\":\"456\",\"database\":null,\"measurement\":null,\"retentionPolicy\":null,\"fields\":[],\"tags\":{},\"groupBy\":{\"time\":null,\"tags\":[]},\"areTagsAccepted\":true,\"rawText\":null}}}",
|
||||
CreatedAt: nowFunc(),
|
||||
UpdatedAt: nowFunc(),
|
||||
}
|
||||
|
||||
return &e
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,12 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
|
||||
mockHandler := mock.NewHandler()
|
||||
|
||||
api.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.DeleteExploration)
|
||||
api.GetSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.GetSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.Exploration)
|
||||
api.GetSourcesIDUsersUserIDExplorationsHandler = operations.GetSourcesIDUsersUserIDExplorationsHandlerFunc(mockHandler.Explorations)
|
||||
api.PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.PatchSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.UpdateExploration)
|
||||
api.PostSourcesIDUsersUserIDExplorationsHandler = operations.PostSourcesIDUsersUserIDExplorationsHandlerFunc(mockHandler.NewExploration)
|
||||
|
||||
api.DeleteDashboardsIDHandler = operations.DeleteDashboardsIDHandlerFunc(func(ctx context.Context, params operations.DeleteDashboardsIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .DeleteDashboardsID has not yet been implemented")
|
||||
})
|
||||
|
@ -85,9 +91,7 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
api.DeleteSourcesIDRolesRoleIDHandler = operations.DeleteSourcesIDRolesRoleIDHandlerFunc(func(ctx context.Context, params operations.DeleteSourcesIDRolesRoleIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .DeleteSourcesIDRolesRoleID has not yet been implemented")
|
||||
})
|
||||
api.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(func(ctx context.Context, params operations.DeleteSourcesIDUsersUserIDExplorationsExplorationIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .DeleteSourcesIDUsersUserIDExplorationsExplorationID has not yet been implemented")
|
||||
})
|
||||
|
||||
api.DeleteSourcesIDUsersUserIDHandler = operations.DeleteSourcesIDUsersUserIDHandlerFunc(func(ctx context.Context, params operations.DeleteSourcesIDUsersUserIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .DeleteSourcesIDUsersUserID has not yet been implemented")
|
||||
})
|
||||
|
@ -114,8 +118,6 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
return middleware.NotImplemented("operation .GetSourcesIDRolesRoleID has not yet been implemented")
|
||||
})
|
||||
|
||||
api.GetSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.GetSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.Exploration)
|
||||
|
||||
api.GetSourcesIDUsersHandler = operations.GetSourcesIDUsersHandlerFunc(func(ctx context.Context, params operations.GetSourcesIDUsersParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .GetSourcesIDUsers has not yet been implemented")
|
||||
})
|
||||
|
@ -123,16 +125,13 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
return middleware.NotImplemented("operation .GetSourcesIDUsersUserID has not yet been implemented")
|
||||
})
|
||||
|
||||
api.GetSourcesIDUsersUserIDExplorationsHandler = operations.GetSourcesIDUsersUserIDExplorationsHandlerFunc(mockHandler.Explorations)
|
||||
api.PatchSourcesIDHandler = operations.PatchSourcesIDHandlerFunc(func(ctx context.Context, params operations.PatchSourcesIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PatchSourcesID has not yet been implemented")
|
||||
})
|
||||
api.PatchSourcesIDRolesRoleIDHandler = operations.PatchSourcesIDRolesRoleIDHandlerFunc(func(ctx context.Context, params operations.PatchSourcesIDRolesRoleIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PatchSourcesIDRolesRoleID has not yet been implemented")
|
||||
})
|
||||
api.PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler = operations.PatchSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(func(ctx context.Context, params operations.PatchSourcesIDUsersUserIDExplorationsExplorationIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PatchSourcesIDUsersUserIDExplorationsExplorationID has not yet been implemented")
|
||||
})
|
||||
|
||||
api.PatchSourcesIDUsersUserIDHandler = operations.PatchSourcesIDUsersUserIDHandlerFunc(func(ctx context.Context, params operations.PatchSourcesIDUsersUserIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PatchSourcesIDUsersUserID has not yet been implemented")
|
||||
})
|
||||
|
@ -160,9 +159,7 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
api.PostSourcesIDUsersHandler = operations.PostSourcesIDUsersHandlerFunc(func(ctx context.Context, params operations.PostSourcesIDUsersParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PostSourcesIDUsers has not yet been implemented")
|
||||
})
|
||||
api.PostSourcesIDUsersUserIDExplorationsHandler = operations.PostSourcesIDUsersUserIDExplorationsHandlerFunc(func(ctx context.Context, params operations.PostSourcesIDUsersUserIDExplorationsParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PostSourcesIDUsersUserIDExplorations has not yet been implemented")
|
||||
})
|
||||
|
||||
api.PutDashboardsIDHandler = operations.PutDashboardsIDHandlerFunc(func(ctx context.Context, params operations.PutDashboardsIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .PutDashboardsID has not yet been implemented")
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue