API: add stars HTTP endpoint (#48612)

Co-authored-by: Ying WANG <ying.wang@grafana.com>
pull/48647/head
Ryan McKinley 4 years ago committed by GitHub
parent b231cbcf86
commit 88eeb878a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      pkg/api/api.go
  2. 26
      pkg/api/stars.go

@ -156,6 +156,7 @@ func (hs *HTTPServer) registerRoutes() {
userRoute.Get("/orgs", routing.Wrap(hs.GetSignedInUserOrgList))
userRoute.Get("/teams", routing.Wrap(hs.GetSignedInUserTeamList))
userRoute.Get("/stars", routing.Wrap(hs.GetStars))
userRoute.Post("/stars/dashboard/:id", routing.Wrap(hs.StarDashboard))
userRoute.Delete("/stars/dashboard/:id", routing.Wrap(hs.UnstarDashboard))

@ -9,6 +9,32 @@ import (
"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 {
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
if err != nil {

Loading…
Cancel
Save