2022-10-26 09:15:14 -05:00
|
|
|
package folderimpl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/folder"
|
|
|
|
)
|
|
|
|
|
2024-01-25 01:27:13 -06:00
|
|
|
type getFoldersQuery struct {
|
|
|
|
folder.GetFoldersQuery
|
|
|
|
ancestorUIDs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetFoldersQuery(q folder.GetFoldersQuery) getFoldersQuery {
|
|
|
|
return getFoldersQuery{
|
|
|
|
GetFoldersQuery: q,
|
|
|
|
ancestorUIDs: []string{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 08:35:49 -05:00
|
|
|
// store is the interface which a folder store must implement.
|
2022-10-26 10:52:01 -05:00
|
|
|
type store interface {
|
|
|
|
// Create creates a folder and returns the newly-created folder.
|
2022-11-03 08:21:41 -05:00
|
|
|
Create(ctx context.Context, cmd folder.CreateFolderCommand) (*folder.Folder, error)
|
2022-10-26 09:15:14 -05:00
|
|
|
|
2024-01-30 10:26:34 -06:00
|
|
|
// Delete folders with the specified UIDs and orgID from the folder store.
|
|
|
|
Delete(ctx context.Context, UIDs []string, orgID int64) error
|
2022-10-26 09:15:14 -05:00
|
|
|
|
2023-04-03 13:24:36 -05:00
|
|
|
// Update updates the given folder's UID, Title, and Description (update mode).
|
|
|
|
// If the NewParentUID field is not nil, it updates also the parent UID (move mode).
|
|
|
|
// If it's a non empty string, it moves the folder under the folder with the specific UID
|
|
|
|
// otherwise, it moves the folder under the root folder (parent_uid column is set to NULL).
|
2022-11-03 08:21:41 -05:00
|
|
|
Update(ctx context.Context, cmd folder.UpdateFolderCommand) (*folder.Folder, error)
|
2022-10-26 09:15:14 -05:00
|
|
|
|
2022-10-26 10:52:01 -05:00
|
|
|
// Get returns a folder.
|
2024-01-18 08:12:49 -06:00
|
|
|
Get(ctx context.Context, q folder.GetFolderQuery) (*folder.Folder, error)
|
2022-10-26 09:15:14 -05:00
|
|
|
|
2022-10-26 10:52:01 -05:00
|
|
|
// GetParents returns an ordered list of parent folder of the given folder.
|
2024-01-18 08:12:49 -06:00
|
|
|
GetParents(ctx context.Context, q folder.GetParentsQuery) ([]*folder.Folder, error)
|
2022-10-26 09:15:14 -05:00
|
|
|
|
2022-10-26 10:52:01 -05:00
|
|
|
// GetChildren returns the set of immediate children folders (depth=1) of the
|
|
|
|
// given folder.
|
2024-01-18 08:12:49 -06:00
|
|
|
GetChildren(ctx context.Context, q folder.GetChildrenQuery) ([]*folder.Folder, error)
|
2022-12-08 07:49:17 -06:00
|
|
|
|
|
|
|
// GetHeight returns the height of the folder tree. When parentUID is set, the function would
|
|
|
|
// verify in the meanwhile that parentUID is not present in the subtree of the folder with the given UID.
|
|
|
|
GetHeight(ctx context.Context, foldrUID string, orgID int64, parentUID *string) (int, error)
|
2023-11-08 08:28:49 -06:00
|
|
|
|
|
|
|
// GetFolders returns folders with given uids
|
2024-01-25 01:27:13 -06:00
|
|
|
GetFolders(ctx context.Context, q getFoldersQuery) ([]*folder.Folder, error)
|
2024-01-30 10:26:34 -06:00
|
|
|
// GetDescendants returns all descendants of a folder
|
|
|
|
GetDescendants(ctx context.Context, orgID int64, anchestor_uid string) ([]*folder.Folder, error)
|
2022-10-26 09:15:14 -05:00
|
|
|
}
|