mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
API: add stars HTTP endpoint (#48612)
Co-authored-by: Ying WANG <ying.wang@grafana.com>
This commit is contained in:
parent
b231cbcf86
commit
88eeb878a4
@ -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…
Reference in New Issue
Block a user