Chore: Remove star model duplicates (#61191)

This commit is contained in:
Kat Yang 2023-01-10 09:56:33 -05:00 committed by GitHub
parent 320266ae63
commit 9a14a7db03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 45 deletions

View File

@ -1,40 +0,0 @@
package models
import "errors"
var ErrCommandValidationFailed = errors.New("command missing required fields")
type Star struct {
Id int64
UserId int64
DashboardId int64
}
// ----------------------
// COMMANDS
type StarDashboardCommand struct {
UserId int64
DashboardId int64
}
type UnstarDashboardCommand struct {
UserId int64
DashboardId int64
}
// ---------------------
// QUERIES
type GetUserStarsQuery struct {
UserId int64
Result map[int64]bool // dashboard ids
}
type IsStarredByUserQuery struct {
UserId int64
DashboardId int64
Result bool
}

View File

@ -22,6 +22,7 @@ import (
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
"github.com/grafana/grafana/pkg/services/star"
"github.com/grafana/grafana/pkg/services/store"
"github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/setting"
@ -963,7 +964,7 @@ func (d *DashboardStore) GetDashboardUIDById(ctx context.Context, query *models.
func (d *DashboardStore) GetDashboards(ctx context.Context, query *models.GetDashboardsQuery) error {
return d.store.WithDbSession(ctx, func(sess *db.Session) error {
if len(query.DashboardIds) == 0 && len(query.DashboardUIds) == 0 {
return models.ErrCommandValidationFailed
return star.ErrCommandValidationFailed
}
var dashboards = make([]*models.Dashboard, 0)

View File

@ -5,9 +5,9 @@ import (
"database/sql"
"errors"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/playlist"
"github.com/grafana/grafana/pkg/services/sqlstore/session"
"github.com/grafana/grafana/pkg/services/star"
)
type sqlxStore struct {
@ -171,7 +171,7 @@ func (s *sqlxStore) List(ctx context.Context, query *playlist.GetPlaylistsQuery)
func (s *sqlxStore) GetItems(ctx context.Context, query *playlist.GetPlaylistItemsByUidQuery) ([]playlist.PlaylistItem, error) {
var playlistItems = make([]playlist.PlaylistItem, 0)
if query.PlaylistUID == "" || query.OrgId == 0 {
return playlistItems, models.ErrCommandValidationFailed
return playlistItems, star.ErrCommandValidationFailed
}
var p = playlist.Playlist{}

View File

@ -4,8 +4,8 @@ import (
"context"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/playlist"
"github.com/grafana/grafana/pkg/services/star"
"github.com/grafana/grafana/pkg/util"
)
@ -171,7 +171,7 @@ func (s *sqlStore) List(ctx context.Context, query *playlist.GetPlaylistsQuery)
func (s *sqlStore) GetItems(ctx context.Context, query *playlist.GetPlaylistItemsByUidQuery) ([]playlist.PlaylistItem, error) {
var playlistItems = make([]playlist.PlaylistItem, 0)
if query.PlaylistUID == "" || query.OrgId == 0 {
return playlistItems, models.ErrCommandValidationFailed
return playlistItems, star.ErrCommandValidationFailed
}
err := s.db.WithDbSession(ctx, func(sess *db.Session) error {
// getQuery the playlist Id