some file moving and struct renaming (#57686)

This commit is contained in:
Kristin Laemmert 2022-10-26 11:52:01 -04:00 committed by GitHub
parent 8917bd57e6
commit 6c982e5b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 80 deletions

View File

@ -0,0 +1,53 @@
package folderimpl
import (
"context"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/setting"
)
type sqlStore struct {
db db.DB
log log.Logger
cfg *setting.Cfg
fm featuremgmt.FeatureManager
}
// sqlStore implements the store interface.
var _ store = (*sqlStore)(nil)
func ProvideStore(db db.DB, cfg *setting.Cfg, features featuremgmt.FeatureManager) *sqlStore {
return &sqlStore{db: db, log: log.New("folder-store"), cfg: cfg, fm: features}
}
func (s *sqlStore) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error) {
panic("not implemented")
}
func (s *sqlStore) Delete(ctx context.Context, uid string, orgID int64) error {
panic("not implemented")
}
func (s *sqlStore) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (*folder.Folder, error) {
panic("not implemented")
}
func (s *sqlStore) Move(ctx context.Context, cmd *folder.MoveFolderCommand) (*folder.Folder, error) {
panic("not implemented")
}
func (s *sqlStore) Get(ctx context.Context, cmd *folder.GetFolderQuery) (*folder.Folder, error) {
panic("not implemented")
}
func (s *sqlStore) GetParents(ctx context.Context, cmd *folder.GetParentsQuery) ([]*folder.Folder, error) {
panic("not implemented")
}
func (s *sqlStore) GetChildren(ctx context.Context, cmd *folder.GetTreeQuery) ([]*folder.Folder, error) {
panic("not implemented")
}

View File

@ -3,51 +3,31 @@ package folderimpl
import ( import (
"context" "context"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/folder" "github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/setting"
) )
type store struct { // Store is the interface which a folder store must implement.
db db.DB type store interface {
log log.Logger // Create creates a folder and returns the newly-created folder.
cfg *setting.Cfg Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error)
fm featuremgmt.FeatureManager
}
// store implements the folder.Store interface. // Delete deletes a folder from the folder store.
var _ folder.Store = (*store)(nil) Delete(ctx context.Context, uid string, orgID int64) error
func ProvideStore(db db.DB, cfg *setting.Cfg, features featuremgmt.FeatureManager) *store { // Update updates the given folder's UID, Title, and Description.
return &store{db: db, log: log.New("folder-store"), cfg: cfg, fm: features} // Use Move to change a dashboard's parent ID.
} Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (*folder.Folder, error)
func (s *store) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error) { // Move changes the given folder's parent folder uid and applies any necessary permissions changes.
panic("not implemented") Move(ctx context.Context, cmd *folder.MoveFolderCommand) (*folder.Folder, error)
}
func (s *store) Delete(ctx context.Context, uid string, orgID int64) error { // Get returns a folder.
panic("not implemented") Get(ctx context.Context, cmd *folder.GetFolderQuery) (*folder.Folder, error)
}
func (s *store) Update(ctx context.Context, cmd *folder.UpdateFolderCommand) (*folder.Folder, error) { // GetParents returns an ordered list of parent folder of the given folder.
panic("not implemented") GetParents(ctx context.Context, cmd *folder.GetParentsQuery) ([]*folder.Folder, error)
}
func (s *store) Move(ctx context.Context, cmd *folder.MoveFolderCommand) (*folder.Folder, error) { // GetChildren returns the set of immediate children folders (depth=1) of the
panic("not implemented") // given folder.
} GetChildren(ctx context.Context, cmd *folder.GetTreeQuery) ([]*folder.Folder, error)
func (s *store) Get(ctx context.Context, cmd *folder.GetFolderCommand) (*folder.Folder, error) {
panic("not implemented")
}
func (s *store) GetParents(ctx context.Context, cmd *folder.GetParentsCommand) ([]*folder.Folder, error) {
panic("not implemented")
}
func (s *store) GetChildren(ctx context.Context, cmd *folder.GetTreeCommand) ([]*folder.Folder, error) {
panic("not implemented")
} }

View File

@ -1,4 +1,4 @@
package foldertest package folderimpl
import ( import (
"context" "context"
@ -12,7 +12,7 @@ type FakeStore struct {
ExpectedError error ExpectedError error
} }
var _ folder.Store = (*FakeStore)(nil) var _ store = (*FakeStore)(nil)
func (f *FakeStore) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error) { func (f *FakeStore) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error) {
return f.ExpectedFolder, f.ExpectedError return f.ExpectedFolder, f.ExpectedError
@ -30,14 +30,14 @@ func (f *FakeStore) Move(ctx context.Context, cmd *folder.MoveFolderCommand) (*f
return f.ExpectedFolder, f.ExpectedError return f.ExpectedFolder, f.ExpectedError
} }
func (f *FakeStore) Get(ctx context.Context, cmd *folder.GetFolderCommand) (*folder.Folder, error) { func (f *FakeStore) Get(ctx context.Context, cmd *folder.GetFolderQuery) (*folder.Folder, error) {
return f.ExpectedFolder, f.ExpectedError return f.ExpectedFolder, f.ExpectedError
} }
func (f *FakeStore) GetParents(ctx context.Context, cmd *folder.GetParentsCommand) ([]*folder.Folder, error) { func (f *FakeStore) GetParents(ctx context.Context, cmd *folder.GetParentsQuery) ([]*folder.Folder, error) {
return f.ExpectedFolders, f.ExpectedError return f.ExpectedFolders, f.ExpectedError
} }
func (f *FakeStore) GetChildren(ctx context.Context, cmd *folder.GetTreeCommand) ([]*folder.Folder, error) { func (f *FakeStore) GetChildren(ctx context.Context, cmd *folder.GetTreeQuery) ([]*folder.Folder, error) {
return f.ExpectedFolders, f.ExpectedError return f.ExpectedFolders, f.ExpectedError
} }

View File

@ -71,26 +71,26 @@ type DeleteFolderCommand struct {
UID string `json:"uid"` UID string `json:"uid"`
} }
// GetFolderCommand is used for all folder Get requests. Only one of UID, ID, or // GetFolderQuery is used for all folder Get requests. Only one of UID, ID, or
// Title should be set; if multilpe fields are set by the caller the dashboard // Title should be set; if multilpe fields are set by the caller the dashboard
// service will select the field with the most specificity, in order: ID, UID, // service will select the field with the most specificity, in order: ID, UID,
// Title. // Title.
type GetFolderCommand struct { type GetFolderQuery struct {
UID *string UID *string
ID *int ID *int
Title *string Title *string
} }
// GetParentsCommand captures the information required by the folder service to // GetParentsQuery captures the information required by the folder service to
// return a list of all parent folders of a given folder. // return a list of all parent folders of a given folder.
type GetParentsCommand struct { type GetParentsQuery struct {
UID string UID string
} }
// GetTreeCommand captures the information required by the folder service to // GetTreeCommand captures the information required by the folder service to
// return a list of child folders of the given folder. // return a list of child folders of the given folder.
type GetTreeCommand struct { type GetTreeQuery struct {
UID string UID string
Depth int64 Depth int64

View File

@ -42,12 +42,12 @@ type NestedFolderService interface {
// request. One of ID, UID, or Title must be included. If multiple values // request. One of ID, UID, or Title must be included. If multiple values
// are included in the request, Grafana will select one in order of // are included in the request, Grafana will select one in order of
// specificity (ID, UID, Title). // specificity (ID, UID, Title).
Get(ctx context.Context, cmd *GetFolderCommand) (*Folder, error) Get(ctx context.Context, cmd *GetFolderQuery) (*Folder, error)
// GetParents returns an ordered list of parent folders for the given // GetParents returns an ordered list of parent folders for the given
// folder, starting with the root node and ending with the requested child // folder, starting with the root node and ending with the requested child
// node. // node.
GetParents(ctx context.Context, cmd *GetParentsCommand) ([]*Folder, error) GetParents(ctx context.Context, cmd *GetParentsQuery) ([]*Folder, error)
// GetTree returns an map containing all child folders starting from the // GetTree returns an map containing all child folders starting from the
// given parent folder UID and descending to the requested depth. Use the // given parent folder UID and descending to the requested depth. Use the
@ -55,5 +55,5 @@ type NestedFolderService interface {
// //
// The map keys are folder uids and the values are the list of child folders // The map keys are folder uids and the values are the list of child folders
// for that parent. // for that parent.
GetTree(ctx context.Context, cmd *GetTreeCommand) (map[string][]*Folder, error) GetTree(ctx context.Context, cmd *GetTreeQuery) (map[string][]*Folder, error)
} }

View File

@ -1,29 +0,0 @@
package folder
import "context"
// Store is the interface which a folder store must implement.
type Store interface {
// Create creates a folder and returns the newly-created folder.
Create(ctx context.Context, cmd *CreateFolderCommand) (*Folder, error)
// Delete deletes a folder from the folder store.
Delete(ctx context.Context, uid string, orgID int64) error
// Update updates the given folder's UID, Title, and Description.
// Use Move to change a dashboard's parent ID.
Update(ctx context.Context, cmd *UpdateFolderCommand) (*Folder, error)
// Move changes the given folder's parent folder uid and applies any necessary permissions changes.
Move(ctx context.Context, cmd *MoveFolderCommand) (*Folder, error)
// Get returns a folder.
Get(ctx context.Context, cmd *GetFolderCommand) (*Folder, error)
// GetParents returns an ordered list of parent folder of the given folder.
GetParents(ctx context.Context, cmd *GetParentsCommand) ([]*Folder, error)
// GetChildren returns the set of immediate children folders (depth=1) of the
// given folder.
GetChildren(ctx context.Context, cmd *GetTreeCommand) ([]*Folder, error)
}