2015-02-02 04:32:32 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-01-15 07:43:20 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
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
|
|
|
)
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
func StarDashboard(c *models.ReqContext) response.Response {
|
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 {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Missing dashboard id", nil)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to star dashboard", err)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Success("Dashboard starred!")
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
func UnstarDashboard(c *models.ReqContext) response.Response {
|
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 {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(400, "Missing dashboard id", nil)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Error(500, "Failed to unstar dashboard", err)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2021-01-15 07:43:20 -06:00
|
|
|
return response.Success("Dashboard unstarred")
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|