forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.go
45 lines (36 loc) · 915 Bytes
/
stars.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package api
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
)
func StarDashboard(c *middleware.Context) {
var cmd = m.StarDashboardCommand{
UserId: c.UserId,
DashboardId: c.ParamsInt64(":id"),
}
if cmd.DashboardId <= 0 {
c.JsonApiErr(400, "Missing dashboard id", nil)
return
}
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to star dashboard", err)
return
}
c.JsonOK("Dashboard starred!")
}
func UnstarDashboard(c *middleware.Context) {
var cmd = m.UnstarDashboardCommand{
UserId: c.UserId,
DashboardId: c.ParamsInt64(":id"),
}
if cmd.DashboardId <= 0 {
c.JsonApiErr(400, "Missing dashboard id", nil)
return
}
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to unstar dashboard", err)
return
}
c.JsonOK("Dashboard unstarred")
}