mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
00c389933b
* Remove bus from team * Fix api team test * Remove bus from team members
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/web"
|
|
)
|
|
|
|
func (hs *HTTPServer) StarDashboard(c *models.ReqContext) response.Response {
|
|
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
|
if err != nil {
|
|
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
|
}
|
|
cmd := models.StarDashboardCommand{UserId: c.UserId, DashboardId: id}
|
|
|
|
if cmd.DashboardId <= 0 {
|
|
return response.Error(400, "Missing dashboard id", nil)
|
|
}
|
|
|
|
if err := hs.SQLStore.StarDashboard(c.Req.Context(), &cmd); err != nil {
|
|
return response.Error(500, "Failed to star dashboard", err)
|
|
}
|
|
|
|
return response.Success("Dashboard starred!")
|
|
}
|
|
|
|
func (hs *HTTPServer) UnstarDashboard(c *models.ReqContext) response.Response {
|
|
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
|
if err != nil {
|
|
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
|
}
|
|
cmd := models.UnstarDashboardCommand{UserId: c.UserId, DashboardId: id}
|
|
|
|
if cmd.DashboardId <= 0 {
|
|
return response.Error(400, "Missing dashboard id", nil)
|
|
}
|
|
|
|
if err := hs.SQLStore.UnstarDashboard(c.Req.Context(), &cmd); err != nil {
|
|
return response.Error(500, "Failed to unstar dashboard", err)
|
|
}
|
|
|
|
return response.Success("Dashboard unstarred")
|
|
}
|