mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 19:12:12 +08:00
API: add stars HTTP endpoint (#48612)
Co-authored-by: Ying WANG <ying.wang@grafana.com>
This commit is contained in:
@ -156,6 +156,7 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
userRoute.Get("/orgs", routing.Wrap(hs.GetSignedInUserOrgList))
|
userRoute.Get("/orgs", routing.Wrap(hs.GetSignedInUserOrgList))
|
||||||
userRoute.Get("/teams", routing.Wrap(hs.GetSignedInUserTeamList))
|
userRoute.Get("/teams", routing.Wrap(hs.GetSignedInUserTeamList))
|
||||||
|
|
||||||
|
userRoute.Get("/stars", routing.Wrap(hs.GetStars))
|
||||||
userRoute.Post("/stars/dashboard/:id", routing.Wrap(hs.StarDashboard))
|
userRoute.Post("/stars/dashboard/:id", routing.Wrap(hs.StarDashboard))
|
||||||
userRoute.Delete("/stars/dashboard/:id", routing.Wrap(hs.UnstarDashboard))
|
userRoute.Delete("/stars/dashboard/:id", routing.Wrap(hs.UnstarDashboard))
|
||||||
|
|
||||||
|
@ -9,6 +9,32 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/web"
|
"github.com/grafana/grafana/pkg/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (hs *HTTPServer) GetStars(c *models.ReqContext) response.Response {
|
||||||
|
query := models.GetUserStarsQuery{
|
||||||
|
UserId: c.SignedInUser.UserId,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := hs.SQLStore.GetUserStars(c.Req.Context(), &query)
|
||||||
|
if err != nil {
|
||||||
|
return response.Error(500, "Failed to get user stars", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
iuserstars := query.Result
|
||||||
|
uids := []string{}
|
||||||
|
for dashboardId := range iuserstars {
|
||||||
|
query := &models.GetDashboardQuery{
|
||||||
|
Id: dashboardId,
|
||||||
|
OrgId: c.OrgId,
|
||||||
|
}
|
||||||
|
err := hs.SQLStore.GetDashboard(c.Req.Context(), query)
|
||||||
|
if err != nil {
|
||||||
|
return response.Error(500, "Failed to get dashboard", err)
|
||||||
|
}
|
||||||
|
uids = append(uids, query.Result.Uid)
|
||||||
|
}
|
||||||
|
return response.JSON(200, uids)
|
||||||
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) StarDashboard(c *models.ReqContext) response.Response {
|
func (hs *HTTPServer) StarDashboard(c *models.ReqContext) response.Response {
|
||||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user