More general backend work, in the middle of the night... Zzzz

This commit is contained in:
Torkel Ödegaard
2014-12-17 03:09:54 +01:00
parent c7ed348ee8
commit adf4e72cf8
6 changed files with 49 additions and 5 deletions
+22 -2
View File
@@ -1,6 +1,7 @@
package api
import (
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
@@ -14,21 +15,40 @@ func GetDataSources(c *middleware.Context) {
c.JsonApiErr(500, "Failed to query datasources", err)
return
}
result := make([]*dtos.DataSource, len(query.Resp))
for _, ds := range query.Resp {
result = append(result, &dtos.DataSource{
Id: ds.Id,
AccountId: ds.AccountId,
Name: ds.Name,
Url: ds.Url,
Type: ds.Type,
Access: ds.Access,
Password: ds.Password,
User: ds.User,
BasicAuth: ds.BasicAuth,
})
}
c.JSON(200, result)
}
func AddDataSource(c *middleware.Context) {
cmd := m.AddDataSourceCommand{}
if !c.JsonBody(&cmd) {
c.JsonApiErr(400, "bad request", nil)
c.JsonApiErr(400, "Validation failed", nil)
return
}
cmd.AccountId = c.Account.Id
err := bus.Dispatch(&cmd)
if err != nil {
c.JsonApiErr(500, "Failed to add datasource", err)
return
}
c.Status(204)
c.JsonOK("Datasource added")
}