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