More general backend work, in the middle of the night... Zzzz
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user