Began work on data source test / validation, #1997 & #2043

This commit is contained in:
Torkel Ödegaard
2015-06-01 12:15:49 +02:00
parent fc43ce657c
commit e2f6633d57
8 changed files with 95 additions and 47 deletions
+3 -4
View File
@@ -107,10 +107,9 @@ func Register(r *macaron.Macaron) {
// Data sources
r.Group("/datasources", func() {
r.Combo("/").
Get(GetDataSources).
Put(bind(m.AddDataSourceCommand{}), AddDataSource).
Post(bind(m.UpdateDataSourceCommand{}), UpdateDataSource)
r.Get("/", GetDataSources)
r.Post("/", bind(m.AddDataSourceCommand{}), AddDataSource)
r.Put("/:id", bind(m.UpdateDataSourceCommand{}), UpdateDataSource)
r.Delete("/:id", DeleteDataSource)
r.Get("/:id", GetDataSourceById)
r.Get("/plugins", GetDataSourcePlugins)
+3 -1
View File
@@ -6,6 +6,7 @@ import (
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/util"
)
func GetDataSources(c *middleware.Context) {
@@ -94,11 +95,12 @@ func AddDataSource(c *middleware.Context, cmd m.AddDataSourceCommand) {
return
}
c.JsonOK("Datasource added")
c.JSON(200, util.DynMap{"message": "Datasource added", "id": cmd.Result.Id})
}
func UpdateDataSource(c *middleware.Context, cmd m.UpdateDataSourceCommand) {
cmd.OrgId = c.OrgId
cmd.Id = c.ParamsInt64(":id")
err := bus.Dispatch(&cmd)
if err != nil {
+1 -1
View File
@@ -69,7 +69,6 @@ type AddDataSourceCommand struct {
// Also acts as api DTO
type UpdateDataSourceCommand struct {
Id int64 `json:"id" binding:"Required"`
Name string `json:"name" binding:"Required"`
Type string `json:"type" binding:"Required"`
Access DsAccess `json:"access" binding:"Required"`
@@ -84,6 +83,7 @@ type UpdateDataSourceCommand struct {
JsonData map[string]interface{} `json:"jsonData"`
OrgId int64 `json:"-"`
Id int64 `json:"-"`
}
type DeleteDataSourceCommand struct {