mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Model refactor (#3915)
* Add mockery config file * Move basic file/folder structs to models * Fix hack due to import loop * Move file interfaces to models * Move folder interfaces to models * Move scene interfaces to models * Move scene marker interfaces to models * Move image interfaces to models * Move gallery interfaces to models * Move gallery chapter interfaces to models * Move studio interfaces to models * Move movie interfaces to models * Move performer interfaces to models * Move tag interfaces to models * Move autotag interfaces to models * Regenerate mocks
This commit is contained in:
@@ -11,15 +11,15 @@ import (
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type FinderImageAliasStashIDGetter interface {
|
||||
Finder
|
||||
GetImage(ctx context.Context, studioID int) ([]byte, error)
|
||||
type FinderImageStashIDGetter interface {
|
||||
models.StudioGetter
|
||||
models.AliasLoader
|
||||
models.StashIDLoader
|
||||
GetImage(ctx context.Context, studioID int) ([]byte, error)
|
||||
}
|
||||
|
||||
// ToJSON converts a Studio object into its JSON equivalent.
|
||||
func ToJSON(ctx context.Context, reader FinderImageAliasStashIDGetter, studio *models.Studio) (*jsonschema.Studio, error) {
|
||||
func ToJSON(ctx context.Context, reader FinderImageStashIDGetter, studio *models.Studio) (*jsonschema.Studio, error) {
|
||||
newStudioJSON := jsonschema.Studio{
|
||||
Name: studio.Name,
|
||||
URL: studio.URL,
|
||||
|
||||
@@ -10,16 +10,15 @@ import (
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type NameFinderCreatorUpdater interface {
|
||||
NameFinderCreator
|
||||
Update(ctx context.Context, updatedStudio *models.Studio) error
|
||||
UpdateImage(ctx context.Context, studioID int, image []byte) error
|
||||
type ImporterReaderWriter interface {
|
||||
models.StudioCreatorUpdater
|
||||
FindByName(ctx context.Context, name string, nocase bool) (*models.Studio, error)
|
||||
}
|
||||
|
||||
var ErrParentStudioNotExist = errors.New("parent studio does not exist")
|
||||
|
||||
type Importer struct {
|
||||
ReaderWriter NameFinderCreatorUpdater
|
||||
ReaderWriter ImporterReaderWriter
|
||||
Input jsonschema.Studio
|
||||
MissingRefBehaviour models.ImportMissingRefEnum
|
||||
|
||||
|
||||
@@ -6,21 +6,7 @@ import (
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type Finder interface {
|
||||
Find(ctx context.Context, id int) (*models.Studio, error)
|
||||
}
|
||||
|
||||
type Queryer interface {
|
||||
Query(ctx context.Context, studioFilter *models.StudioFilterType, findFilter *models.FindFilterType) ([]*models.Studio, int, error)
|
||||
}
|
||||
|
||||
type FinderQueryer interface {
|
||||
Finder
|
||||
Queryer
|
||||
models.AliasLoader
|
||||
}
|
||||
|
||||
func ByName(ctx context.Context, qb Queryer, name string) (*models.Studio, error) {
|
||||
func ByName(ctx context.Context, qb models.StudioQueryer, name string) (*models.Studio, error) {
|
||||
f := &models.StudioFilterType{
|
||||
Name: &models.StringCriterionInput{
|
||||
Value: name,
|
||||
@@ -44,7 +30,7 @@ func ByName(ctx context.Context, qb Queryer, name string) (*models.Studio, error
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func ByAlias(ctx context.Context, qb Queryer, alias string) (*models.Studio, error) {
|
||||
func ByAlias(ctx context.Context, qb models.StudioQueryer, alias string) (*models.Studio, error) {
|
||||
f := &models.StudioFilterType{
|
||||
Aliases: &models.StringCriterionInput{
|
||||
Value: alias,
|
||||
|
||||
@@ -12,11 +12,6 @@ var (
|
||||
ErrStudioOwnAncestor = errors.New("studio cannot be an ancestor of itself")
|
||||
)
|
||||
|
||||
type NameFinderCreator interface {
|
||||
FindByName(ctx context.Context, name string, nocase bool) (*models.Studio, error)
|
||||
Create(ctx context.Context, newStudio *models.Studio) error
|
||||
}
|
||||
|
||||
type NameExistsError struct {
|
||||
Name string
|
||||
}
|
||||
@@ -36,7 +31,7 @@ func (e *NameUsedByAliasError) Error() string {
|
||||
|
||||
// EnsureStudioNameUnique returns an error if the studio name provided
|
||||
// is used as a name or alias of another existing tag.
|
||||
func EnsureStudioNameUnique(ctx context.Context, id int, name string, qb Queryer) error {
|
||||
func EnsureStudioNameUnique(ctx context.Context, id int, name string, qb models.StudioQueryer) error {
|
||||
// ensure name is unique
|
||||
sameNameStudio, err := ByName(ctx, qb, name)
|
||||
if err != nil {
|
||||
@@ -65,7 +60,7 @@ func EnsureStudioNameUnique(ctx context.Context, id int, name string, qb Queryer
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnsureAliasesUnique(ctx context.Context, id int, aliases []string, qb Queryer) error {
|
||||
func EnsureAliasesUnique(ctx context.Context, id int, aliases []string, qb models.StudioQueryer) error {
|
||||
for _, a := range aliases {
|
||||
if err := EnsureStudioNameUnique(ctx, id, a, qb); err != nil {
|
||||
return err
|
||||
@@ -75,11 +70,17 @@ func EnsureAliasesUnique(ctx context.Context, id int, aliases []string, qb Query
|
||||
return nil
|
||||
}
|
||||
|
||||
type ValidateModifyReader interface {
|
||||
models.StudioGetter
|
||||
models.StudioQueryer
|
||||
models.AliasLoader
|
||||
}
|
||||
|
||||
// Checks to make sure that:
|
||||
// 1. The studio exists locally
|
||||
// 2. The studio is not its own ancestor
|
||||
// 3. The studio's aliases are unique
|
||||
func ValidateModify(ctx context.Context, s models.StudioPartial, qb FinderQueryer) error {
|
||||
func ValidateModify(ctx context.Context, s models.StudioPartial, qb ValidateModifyReader) error {
|
||||
existing, err := qb.Find(ctx, s.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -110,7 +111,7 @@ func ValidateModify(ctx context.Context, s models.StudioPartial, qb FinderQuerye
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateParent(ctx context.Context, studioID int, newParentID int, qb FinderQueryer) error {
|
||||
func validateParent(ctx context.Context, studioID int, newParentID int, qb models.StudioGetter) error {
|
||||
if newParentID == studioID {
|
||||
return ErrStudioOwnAncestor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user