grafana/pkg/api/stars.go
idafurjes 00c389933b
Chore: Remove bus from team (#44218)
* Remove bus from team

* Fix api team test

* Remove bus from team members
2022-01-24 11:52:35 +01:00

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")
}