mirror of https://github.com/grafana/grafana
Query history: Create API to delete query from query history (#44653)
* Query history: Add delete and refactor * Update docs/sources/http_api/query_history.md Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>pull/44921/head
parent
1680e284e5
commit
0f362f8dfc
@ -1,21 +1,48 @@ |
||||
package queryhistory |
||||
|
||||
import ( |
||||
"errors" |
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson" |
||||
) |
||||
|
||||
var ( |
||||
ErrQueryNotFound = errors.New("query in query history not found") |
||||
) |
||||
|
||||
type QueryHistory struct { |
||||
Id int64 `json:"id"` |
||||
Uid string `json:"uid"` |
||||
DatasourceUid string `json:"datasourceUid"` |
||||
OrgId int64 `json:"orgId"` |
||||
ID int64 `xorm:"pk autoincr 'id'"` |
||||
UID string `xorm:"uid"` |
||||
DatasourceUID string `xorm:"datasource_uid"` |
||||
OrgID int64 `xorm:"org_id"` |
||||
CreatedBy int64 |
||||
CreatedAt int64 |
||||
Comment string |
||||
Queries *simplejson.Json |
||||
} |
||||
|
||||
type CreateQueryInQueryHistoryCommand struct { |
||||
DatasourceUID string `json:"datasourceUid"` |
||||
Queries *simplejson.Json `json:"queries"` |
||||
} |
||||
|
||||
type QueryHistoryDTO struct { |
||||
UID string `json:"uid"` |
||||
DatasourceUID string `json:"datasourceUid"` |
||||
CreatedBy int64 `json:"createdBy"` |
||||
CreatedAt int64 `json:"createdAt"` |
||||
Comment string `json:"comment"` |
||||
Queries *simplejson.Json `json:"queries"` |
||||
Starred bool `json:"starred"` |
||||
} |
||||
|
||||
type CreateQueryInQueryHistoryCommand struct { |
||||
DatasourceUid string `json:"datasourceUid"` |
||||
Queries *simplejson.Json `json:"queries"` |
||||
// QueryHistoryResponse is a response struct for QueryHistoryDTO
|
||||
type QueryHistoryResponse struct { |
||||
Result QueryHistoryDTO `json:"result"` |
||||
} |
||||
|
||||
// DeleteQueryFromQueryHistoryResponse is the response struct for deleting a query from query history
|
||||
type DeleteQueryFromQueryHistoryResponse struct { |
||||
ID int64 `json:"id"` |
||||
Message string `json:"message"` |
||||
} |
||||
|
@ -0,0 +1,23 @@ |
||||
package queryhistory |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/grafana/grafana/pkg/web" |
||||
"github.com/stretchr/testify/require" |
||||
) |
||||
|
||||
func TestDeleteQueryFromQueryHistory(t *testing.T) { |
||||
testScenarioWithQueryInQueryHistory(t, "When users tries to delete query in query history that does not exist, it should fail", |
||||
func(t *testing.T, sc scenarioContext) { |
||||
resp := sc.service.deleteHandler(sc.reqContext) |
||||
require.Equal(t, 404, resp.Status()) |
||||
}) |
||||
|
||||
testScenarioWithQueryInQueryHistory(t, "When users tries to delete query in query history that exists, it should succeed", |
||||
func(t *testing.T, sc scenarioContext) { |
||||
sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID}) |
||||
resp := sc.service.deleteHandler(sc.reqContext) |
||||
require.Equal(t, 200, resp.Status()) |
||||
}) |
||||
} |
Loading…
Reference in new issue