grafana/pkg/api/stars.go

40 lines
930 B
Go
Raw Normal View History

package api
import (
2015-02-05 03:37:13 -06:00
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
)
func StarDashboard(c *models.ReqContext) Response {
if !c.IsSignedIn {
2018-03-22 16:13:46 -05:00
return Error(412, "You need to sign in to star dashboards", nil)
}
cmd := models.StarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
if cmd.DashboardId <= 0 {
2018-03-22 16:13:46 -05:00
return Error(400, "Missing dashboard id", nil)
}
if err := bus.Dispatch(&cmd); err != nil {
2018-03-22 16:13:46 -05:00
return Error(500, "Failed to star dashboard", err)
}
2018-03-22 16:13:46 -05:00
return Success("Dashboard starred!")
}
func UnstarDashboard(c *models.ReqContext) Response {
cmd := models.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
if cmd.DashboardId <= 0 {
2018-03-22 16:13:46 -05:00
return Error(400, "Missing dashboard id", nil)
}
if err := bus.Dispatch(&cmd); err != nil {
2018-03-22 16:13:46 -05:00
return Error(500, "Failed to unstar dashboard", err)
}
2018-03-22 16:13:46 -05:00
return Success("Dashboard unstarred")
}