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:
DingDongSoLong4
2023-09-01 02:39:29 +02:00
committed by GitHub
parent 20520a58b4
commit c364346a59
185 changed files with 3840 additions and 2559 deletions

View File

@@ -6,20 +6,10 @@ import (
"fmt"
"time"
"github.com/stashapp/stash/pkg/file"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
type Updater interface {
PartialUpdater
UpdateCover(ctx context.Context, sceneID int, cover []byte) error
}
type PartialUpdater interface {
UpdatePartial(ctx context.Context, id int, updatedScene models.ScenePartial) (*models.Scene, error)
}
var ErrEmptyUpdater = errors.New("no fields have been set")
// UpdateSet is used to update a scene and its relationships.
@@ -46,7 +36,7 @@ func (u *UpdateSet) IsEmpty() bool {
// Update updates a scene by updating the fields in the Partial field, then
// updates non-nil relationships. Returns an error if there is no work to
// be done.
func (u *UpdateSet) Update(ctx context.Context, qb Updater) (*models.Scene, error) {
func (u *UpdateSet) Update(ctx context.Context, qb models.SceneUpdater) (*models.Scene, error) {
if u.IsEmpty() {
return nil, ErrEmptyUpdater
}
@@ -83,7 +73,7 @@ func (u UpdateSet) UpdateInput() models.SceneUpdateInput {
return ret
}
func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, performerID int) error {
func AddPerformer(ctx context.Context, qb models.SceneUpdater, o *models.Scene, performerID int) error {
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
PerformerIDs: &models.UpdateIDs{
IDs: []int{performerID},
@@ -93,7 +83,7 @@ func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, perfo
return err
}
func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int) error {
func AddTag(ctx context.Context, qb models.SceneUpdater, o *models.Scene, tagID int) error {
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{tagID},
@@ -103,7 +93,7 @@ func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int)
return err
}
func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, galleryID int) error {
func AddGallery(ctx context.Context, qb models.SceneUpdater, o *models.Scene, galleryID int) error {
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
TagIDs: &models.UpdateIDs{
IDs: []int{galleryID},
@@ -113,7 +103,7 @@ func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, gallery
return err
}
func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) error {
func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID models.FileID) error {
// ensure file isn't a primary file and that it is a video file
f, err := s.File.Find(ctx, fileID)
if err != nil {
@@ -121,7 +111,7 @@ func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) e
}
ff := f[0]
if _, ok := ff.(*file.VideoFile); !ok {
if _, ok := ff.(*models.VideoFile); !ok {
return fmt.Errorf("%s is not a video file", ff.Base().Path)
}
@@ -134,5 +124,5 @@ func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) e
return errors.New("cannot reassign primary file")
}
return s.Repository.AssignFiles(ctx, sceneID, []file.ID{fileID})
return s.Repository.AssignFiles(ctx, sceneID, []models.FileID{fileID})
}