Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
7f4f38e7
Commit
7f4f38e7
authored
Feb 10, 2017
by
Carl Bergquist
Committed by
GitHub
Feb 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7519 from huydx/master
(feat) support datasource delete by name api
parents
f147ac05
143cbe92
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
9 deletions
+51
-9
pkg/api/api.go
+2
-1
pkg/api/datasources.go
+21
-2
pkg/models/datasource.go
+6
-1
pkg/services/sqlstore/datasource.go
+11
-2
pkg/services/sqlstore/datasource_test.go
+11
-3
No files found.
pkg/api/api.go
View file @
7f4f38e7
...
...
@@ -198,7 +198,8 @@ func (hs *HttpServer) registerRoutes() {
r
.
Get
(
"/"
,
GetDataSources
)
r
.
Post
(
"/"
,
quota
(
"data_source"
),
bind
(
m
.
AddDataSourceCommand
{}),
AddDataSource
)
r
.
Put
(
"/:id"
,
bind
(
m
.
UpdateDataSourceCommand
{}),
wrap
(
UpdateDataSource
))
r
.
Delete
(
"/:id"
,
DeleteDataSource
)
r
.
Delete
(
"/:id"
,
DeleteDataSourceById
)
r
.
Delete
(
"/name/:name"
,
DeleteDataSourceByName
)
r
.
Get
(
"/:id"
,
wrap
(
GetDataSourceById
))
r
.
Get
(
"/name/:name"
,
wrap
(
GetDataSourceByName
))
},
reqOrgAdmin
)
...
...
pkg/api/datasources.go
View file @
7f4f38e7
...
...
@@ -68,7 +68,7 @@ func GetDataSourceById(c *middleware.Context) Response {
return
Json
(
200
,
&
dtos
)
}
func
DeleteDataSource
(
c
*
middleware
.
Context
)
{
func
DeleteDataSource
ById
(
c
*
middleware
.
Context
)
{
id
:=
c
.
ParamsInt64
(
":id"
)
if
id
<=
0
{
...
...
@@ -76,7 +76,26 @@ func DeleteDataSource(c *middleware.Context) {
return
}
cmd
:=
&
m
.
DeleteDataSourceCommand
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
cmd
:=
&
m
.
DeleteDataSourceByIdCommand
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to delete datasource"
,
err
)
return
}
c
.
JsonOK
(
"Data source deleted"
)
}
func
DeleteDataSourceByName
(
c
*
middleware
.
Context
)
{
name
:=
c
.
Params
(
":name"
)
if
name
==
""
{
c
.
JsonApiErr
(
400
,
"Missing valid datasource name"
,
nil
)
return
}
cmd
:=
&
m
.
DeleteDataSourceByNameCommand
{
Name
:
name
,
OrgId
:
c
.
OrgId
}
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
{
...
...
pkg/models/datasource.go
View file @
7f4f38e7
...
...
@@ -120,11 +120,16 @@ type UpdateDataSourceCommand struct {
Id
int64
`json:"-"`
}
type
DeleteDataSourceCommand
struct
{
type
DeleteDataSource
ById
Command
struct
{
Id
int64
OrgId
int64
}
type
DeleteDataSourceByNameCommand
struct
{
Name
string
OrgId
int64
}
// ---------------------
// QUERIES
...
...
pkg/services/sqlstore/datasource.go
View file @
7f4f38e7
...
...
@@ -13,7 +13,8 @@ import (
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetDataSources
)
bus
.
AddHandler
(
"sql"
,
AddDataSource
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSource
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSourceById
)
bus
.
AddHandler
(
"sql"
,
DeleteDataSourceByName
)
bus
.
AddHandler
(
"sql"
,
UpdateDataSource
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceById
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceByName
)
...
...
@@ -50,7 +51,7 @@ func GetDataSources(query *m.GetDataSourcesQuery) error {
return
sess
.
Find
(
&
query
.
Result
)
}
func
DeleteDataSource
(
cmd
*
m
.
DeleteDataSource
Command
)
error
{
func
DeleteDataSource
ById
(
cmd
*
m
.
DeleteDataSourceById
Command
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM data_source WHERE id=? and org_id=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
Id
,
cmd
.
OrgId
)
...
...
@@ -58,6 +59,14 @@ func DeleteDataSource(cmd *m.DeleteDataSourceCommand) error {
})
}
func
DeleteDataSourceByName
(
cmd
*
m
.
DeleteDataSourceByNameCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
var
rawSql
=
"DELETE FROM data_source WHERE name=? and org_id=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
cmd
.
Name
,
cmd
.
OrgId
)
return
err
})
}
func
AddDataSource
(
cmd
*
m
.
AddDataSourceCommand
)
error
{
return
inTransaction
(
func
(
sess
*
xorm
.
Session
)
error
{
...
...
pkg/services/sqlstore/datasource_test.go
View file @
7f4f38e7
...
...
@@ -79,8 +79,16 @@ func TestDataAccess(t *testing.T) {
ds
:=
query
.
Result
[
0
]
Convey
(
"Can delete datasource"
,
func
()
{
err
:=
DeleteDataSource
(
&
m
.
DeleteDataSourceCommand
{
Id
:
ds
.
Id
,
OrgId
:
ds
.
OrgId
})
Convey
(
"Can delete datasource by id"
,
func
()
{
err
:=
DeleteDataSourceById
(
&
m
.
DeleteDataSourceByIdCommand
{
Id
:
ds
.
Id
,
OrgId
:
ds
.
OrgId
})
So
(
err
,
ShouldBeNil
)
GetDataSources
(
&
query
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
0
)
})
Convey
(
"Can delete datasource by name"
,
func
()
{
err
:=
DeleteDataSourceByName
(
&
m
.
DeleteDataSourceByNameCommand
{
Name
:
ds
.
Name
,
OrgId
:
ds
.
OrgId
})
So
(
err
,
ShouldBeNil
)
GetDataSources
(
&
query
)
...
...
@@ -88,7 +96,7 @@ func TestDataAccess(t *testing.T) {
})
Convey
(
"Can not delete datasource with wrong orgId"
,
func
()
{
err
:=
DeleteDataSource
(
&
m
.
DeleteDataSource
Command
{
Id
:
ds
.
Id
,
OrgId
:
123123
})
err
:=
DeleteDataSource
ById
(
&
m
.
DeleteDataSourceById
Command
{
Id
:
ds
.
Id
,
OrgId
:
123123
})
So
(
err
,
ShouldBeNil
)
GetDataSources
(
&
query
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment