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"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2015-02-02 04:32:32 -06:00
|
|
|
)
|
|
|
|
|
2018-03-07 10:54:50 -06:00
|
|
|
func StarDashboard(c *m.ReqContext) Response {
|
2015-05-13 02:58:45 -05:00
|
|
|
if !c.IsSignedIn {
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiError(412, "You need to sign in to star dashboards", nil)
|
2015-05-13 02:58:45 -05:00
|
|
|
}
|
|
|
|
|
2015-05-20 07:59:38 -05:00
|
|
|
cmd := m.StarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
|
2015-02-02 04:32:32 -06:00
|
|
|
|
|
|
|
if cmd.DashboardId <= 0 {
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiError(400, "Missing dashboard id", nil)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiError(500, "Failed to star dashboard", err)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiSuccess("Dashboard starred!")
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2018-03-07 10:54:50 -06:00
|
|
|
func UnstarDashboard(c *m.ReqContext) Response {
|
2015-05-20 07:59:38 -05:00
|
|
|
|
|
|
|
cmd := m.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
|
2015-02-02 04:32:32 -06:00
|
|
|
|
|
|
|
if cmd.DashboardId <= 0 {
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiError(400, "Missing dashboard id", nil)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiError(500, "Failed to unstar dashboard", err)
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|
|
|
|
|
2015-05-20 07:59:38 -05:00
|
|
|
return ApiSuccess("Dashboard unstarred")
|
2015-02-02 04:32:32 -06:00
|
|
|
}
|