mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +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:
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"gopkg.in/guregu/null.v4"
|
||||
@@ -150,7 +149,7 @@ func (qb *ImageStore) selectDataset() *goqu.SelectDataset {
|
||||
checksum,
|
||||
goqu.On(
|
||||
checksum.Col(fileIDColumn).Eq(imagesFilesJoinTable.Col(fileIDColumn)),
|
||||
checksum.Col("type").Eq(file.FingerprintTypeMD5),
|
||||
checksum.Col("type").Eq(models.FingerprintTypeMD5),
|
||||
),
|
||||
).Select(
|
||||
qb.table().All(),
|
||||
@@ -271,7 +270,7 @@ func (qb *ImageStore) Update(ctx context.Context, updatedObject *models.Image) e
|
||||
}
|
||||
|
||||
if updatedObject.Files.Loaded() {
|
||||
fileIDs := make([]file.ID, len(updatedObject.Files.List()))
|
||||
fileIDs := make([]models.FileID, len(updatedObject.Files.List()))
|
||||
for i, f := range updatedObject.Files.List() {
|
||||
fileIDs[i] = f.Base().ID
|
||||
}
|
||||
@@ -389,7 +388,7 @@ func (qb *ImageStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]*mo
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]file.File, error) {
|
||||
func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]models.File, error) {
|
||||
fileIDs, err := qb.filesRepository().get(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -404,12 +403,12 @@ func (qb *ImageStore) GetFiles(ctx context.Context, id int) ([]file.File, error)
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]file.ID, error) {
|
||||
func (qb *ImageStore) GetManyFileIDs(ctx context.Context, ids []int) ([][]models.FileID, error) {
|
||||
const primaryOnly = false
|
||||
return qb.filesRepository().getMany(ctx, ids, primaryOnly)
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
|
||||
sq := dialect.From(table).
|
||||
@@ -427,14 +426,14 @@ func (qb *ImageStore) FindByFileID(ctx context.Context, fileID file.ID) ([]*mode
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) CountByFileID(ctx context.Context, fileID file.ID) (int, error) {
|
||||
func (qb *ImageStore) CountByFileID(ctx context.Context, fileID models.FileID) (int, error) {
|
||||
joinTable := imagesFilesJoinTable
|
||||
|
||||
q := dialect.Select(goqu.COUNT("*")).From(joinTable).Where(joinTable.Col(fileIDColumn).Eq(fileID))
|
||||
return count(ctx, q)
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fingerprintTable := fingerprintTableMgr.table
|
||||
|
||||
@@ -467,9 +466,9 @@ func (qb *ImageStore) FindByFingerprints(ctx context.Context, fp []file.Fingerpr
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByChecksum(ctx context.Context, checksum string) ([]*models.Image, error) {
|
||||
return qb.FindByFingerprints(ctx, []file.Fingerprint{
|
||||
return qb.FindByFingerprints(ctx, []models.Fingerprint{
|
||||
{
|
||||
Type: file.FingerprintTypeMD5,
|
||||
Type: models.FingerprintTypeMD5,
|
||||
Fingerprint: checksum,
|
||||
},
|
||||
})
|
||||
@@ -523,7 +522,7 @@ func (qb *ImageStore) OCountByPerformerID(ctx context.Context, performerID int)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID file.FolderID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID models.FolderID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fileTable := goqu.T(fileTable)
|
||||
|
||||
@@ -548,7 +547,7 @@ func (qb *ImageStore) FindByFolderID(ctx context.Context, folderID file.FolderID
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *ImageStore) FindByZipFileID(ctx context.Context, zipFileID file.ID) ([]*models.Image, error) {
|
||||
func (qb *ImageStore) FindByZipFileID(ctx context.Context, zipFileID models.FileID) ([]*models.Image, error) {
|
||||
table := qb.table()
|
||||
fileTable := goqu.T(fileTable)
|
||||
|
||||
@@ -1043,9 +1042,9 @@ func (qb *ImageStore) filesRepository() *filesRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (qb *ImageStore) AddFileID(ctx context.Context, id int, fileID file.ID) error {
|
||||
func (qb *ImageStore) AddFileID(ctx context.Context, id int, fileID models.FileID) error {
|
||||
const firstPrimary = false
|
||||
return imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []file.ID{fileID})
|
||||
return imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, []models.FileID{fileID})
|
||||
}
|
||||
|
||||
func (qb *ImageStore) GetGalleryIDs(ctx context.Context, imageID int) ([]int, error) {
|
||||
|
||||
Reference in New Issue
Block a user