graph(add annotation): initial backend implementation #1286

This commit is contained in:
Alexander Zobnin
2017-04-10 20:22:58 +03:00
parent 362860f687
commit d553498a33
5 changed files with 47 additions and 4 deletions
+21
View File
@@ -45,6 +45,27 @@ func GetAnnotations(c *middleware.Context) Response {
return Json(200, result)
}
func PostAnnotation(c *middleware.Context, cmd dtos.PostAnnotationsCmd) Response {
repo := annotations.GetRepository()
item := annotations.Item{
OrgId: c.OrgId,
DashboardId: cmd.DashboardId,
PanelId: cmd.PanelId,
Epoch: cmd.Time / 1000,
Title: cmd.Title,
Text: cmd.Text,
}
err := repo.Save(&item)
if err != nil {
return ApiError(500, "Failed to save annotation", err)
}
return ApiSuccess("Annotation added")
}
func DeleteAnnotations(c *middleware.Context, cmd dtos.DeleteAnnotationsCmd) Response {
repo := annotations.GetRepository()
+1
View File
@@ -277,6 +277,7 @@ func (hs *HttpServer) registerRoutes() {
}, reqEditorRole)
r.Get("/annotations", wrap(GetAnnotations))
r.Post("/annotations", bind(dtos.PostAnnotationsCmd{}), wrap(PostAnnotation))
r.Post("/annotations/mass-delete", reqOrgAdmin, bind(dtos.DeleteAnnotationsCmd{}), wrap(DeleteAnnotations))
// error test
+8
View File
@@ -16,6 +16,14 @@ type Annotation struct {
Data *simplejson.Json `json:"data"`
}
type PostAnnotationsCmd struct {
DashboardId int64 `json:"dashboardId"`
PanelId int64 `json:"panelId"`
Time int64 `json:"time"`
Title string `json:"title"`
Text string `json:"text"`
}
type DeleteAnnotationsCmd struct {
AlertId int64 `json:"alertId"`
DashboardId int64 `json:"dashboardId"`