API: add stars HTTP endpoint (#48612)

Co-authored-by: Ying WANG <ying.wang@grafana.com>
This commit is contained in:
Ryan McKinley 2022-05-03 08:52:19 -07:00 committed by GitHub
parent b231cbcf86
commit 88eeb878a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -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))

View File

@ -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 {