Update data sources now work, #8
This commit is contained in:
@@ -16,9 +16,9 @@ func GetDataSources(c *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result := make([]*dtos.DataSource, len(query.Resp))
|
||||
for _, ds := range query.Resp {
|
||||
result = append(result, &dtos.DataSource{
|
||||
result := make([]*dtos.DataSource, len(query.Result))
|
||||
for i, ds := range query.Result {
|
||||
result[i] = &dtos.DataSource{
|
||||
Id: ds.Id,
|
||||
AccountId: ds.AccountId,
|
||||
Name: ds.Name,
|
||||
@@ -28,12 +28,31 @@ func GetDataSources(c *middleware.Context) {
|
||||
Password: ds.Password,
|
||||
User: ds.User,
|
||||
BasicAuth: ds.BasicAuth,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, result)
|
||||
}
|
||||
|
||||
func DeleteDataSource(c *middleware.Context) {
|
||||
id := c.ParamsInt64(":id")
|
||||
|
||||
if id <= 0 {
|
||||
c.JsonApiErr(400, "Missing valid datasource id", nil)
|
||||
return
|
||||
}
|
||||
|
||||
cmd := &m.DeleteDataSourceCommand{Id: id, AccountId: c.UserAccount.Id}
|
||||
|
||||
err := bus.Dispatch(cmd)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to delete datasource", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JsonOK("Data source deleted")
|
||||
}
|
||||
|
||||
func AddDataSource(c *middleware.Context) {
|
||||
cmd := m.AddDataSourceCommand{}
|
||||
|
||||
@@ -52,3 +71,22 @@ func AddDataSource(c *middleware.Context) {
|
||||
|
||||
c.JsonOK("Datasource added")
|
||||
}
|
||||
|
||||
func UpdateDataSource(c *middleware.Context) {
|
||||
cmd := m.UpdateDataSourceCommand{}
|
||||
|
||||
if !c.JsonBody(&cmd) {
|
||||
c.JsonApiErr(400, "Validation failed", nil)
|
||||
return
|
||||
}
|
||||
|
||||
cmd.AccountId = c.Account.Id
|
||||
|
||||
err := bus.Dispatch(&cmd)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to update datasource", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JsonOK("Datasource updated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user