mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 03:09:03 +08:00
integrat star service into APIs (#49220)
This commit is contained in:
@ -23,6 +23,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
pref "github.com/grafana/grafana/pkg/services/preference"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@ -37,12 +38,8 @@ func (hs *HTTPServer) isDashboardStarredByUser(c *models.ReqContext, dashID int6
|
||||
return false, nil
|
||||
}
|
||||
|
||||
query := models.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashID}
|
||||
if err := hs.SQLStore.IsStarredByUserCtx(c.Req.Context(), &query); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return query.Result, nil
|
||||
query := star.IsStarredByUserQuery{UserID: c.UserId, DashboardID: dashID}
|
||||
return hs.starService.IsStarredByUser(c.Req.Context(), &query)
|
||||
}
|
||||
|
||||
func dashboardGuardianResponse(err error) response.Response {
|
||||
|
@ -64,6 +64,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/teamguardian"
|
||||
"github.com/grafana/grafana/pkg/services/thumbs"
|
||||
@ -152,6 +153,7 @@ type HTTPServer struct {
|
||||
entityEventsService store.EntityEventsService
|
||||
folderPermissionsService accesscontrol.FolderPermissionsService
|
||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService
|
||||
starService star.Service
|
||||
}
|
||||
|
||||
type ServerOptions struct {
|
||||
@ -185,7 +187,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
dashboardsnapshotsService *dashboardsnapshots.Service, commentsService *comments.Service, pluginSettings *pluginSettings.Service,
|
||||
avatarCacheServer *avatar.AvatarCacheServer, preferenceService pref.Service, entityEventsService store.EntityEventsService,
|
||||
teamsPermissionsService accesscontrol.TeamPermissionsService, folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService,
|
||||
dashboardPermissionsService accesscontrol.DashboardPermissionsService, starService star.Service,
|
||||
) (*HTTPServer, error) {
|
||||
web.Env = cfg.Env
|
||||
m := web.New()
|
||||
@ -262,6 +264,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
entityEventsService: entityEventsService,
|
||||
folderPermissionsService: folderPermissionsService,
|
||||
dashboardPermissionsService: dashboardPermissionsService,
|
||||
starService: starService,
|
||||
}
|
||||
if hs.Listener != nil {
|
||||
hs.log.Debug("Using provided listener")
|
||||
|
@ -6,22 +6,22 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
func (hs *HTTPServer) GetStars(c *models.ReqContext) response.Response {
|
||||
query := models.GetUserStarsQuery{
|
||||
UserId: c.SignedInUser.UserId,
|
||||
query := star.GetUserStarsQuery{
|
||||
UserID: c.SignedInUser.UserId,
|
||||
}
|
||||
|
||||
err := hs.SQLStore.GetUserStars(c.Req.Context(), &query)
|
||||
iuserstars, err := hs.starService.GetByUser(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 {
|
||||
for dashboardId := range iuserstars.UserStars {
|
||||
query := &models.GetDashboardQuery{
|
||||
Id: dashboardId,
|
||||
OrgId: c.OrgId,
|
||||
@ -40,13 +40,13 @@ func (hs *HTTPServer) StarDashboard(c *models.ReqContext) response.Response {
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
cmd := models.StarDashboardCommand{UserId: c.UserId, DashboardId: id}
|
||||
cmd := star.StarDashboardCommand{UserID: c.UserId, DashboardID: id}
|
||||
|
||||
if cmd.DashboardId <= 0 {
|
||||
if cmd.DashboardID <= 0 {
|
||||
return response.Error(400, "Missing dashboard id", nil)
|
||||
}
|
||||
|
||||
if err := hs.SQLStore.StarDashboard(c.Req.Context(), &cmd); err != nil {
|
||||
if err := hs.starService.Add(c.Req.Context(), &cmd); err != nil {
|
||||
return response.Error(500, "Failed to star dashboard", err)
|
||||
}
|
||||
|
||||
@ -58,13 +58,13 @@ func (hs *HTTPServer) UnstarDashboard(c *models.ReqContext) response.Response {
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
cmd := models.UnstarDashboardCommand{UserId: c.UserId, DashboardId: id}
|
||||
cmd := star.UnstarDashboardCommand{UserID: c.UserId, DashboardID: id}
|
||||
|
||||
if cmd.DashboardId <= 0 {
|
||||
if cmd.DashboardID <= 0 {
|
||||
return response.Error(400, "Missing dashboard id", nil)
|
||||
}
|
||||
|
||||
if err := hs.SQLStore.UnstarDashboard(c.Req.Context(), &cmd); err != nil {
|
||||
if err := hs.starService.Delete(c.Req.Context(), &cmd); err != nil {
|
||||
return response.Error(500, "Failed to unstar dashboard", err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user