mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
3d41267fc4
* Chore: moves common and response into separate packages * Chore: moves common and response into separate packages * Update pkg/api/utils/common.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: changes after PR comments * Chore: move wrap to routing package * Chore: move functions in common to response package * Chore: move functions in common to response package * Chore: formats imports Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func StarDashboard(c *models.ReqContext) response.Response {
|
|
if !c.IsSignedIn {
|
|
return response.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 {
|
|
return response.Error(400, "Missing dashboard id", nil)
|
|
}
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
return response.Error(500, "Failed to star dashboard", err)
|
|
}
|
|
|
|
return response.Success("Dashboard starred!")
|
|
}
|
|
|
|
func UnstarDashboard(c *models.ReqContext) response.Response {
|
|
cmd := models.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
|
|
|
|
if cmd.DashboardId <= 0 {
|
|
return response.Error(400, "Missing dashboard id", nil)
|
|
}
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
return response.Error(500, "Failed to unstar dashboard", err)
|
|
}
|
|
|
|
return response.Success("Dashboard unstarred")
|
|
}
|