mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Model refactor, part 2 (#4092)
* Move conversions into changesetTranslator * Improve mutation error messages * Use models.New and models.NewPartial everywhere * Replace getStashIDsFor functions * Remove ImageCreateInput * Remove unused parameters * Refactor matching functions --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -160,18 +160,18 @@ func (qb *ImageStore) selectDataset() *goqu.SelectDataset {
|
||||
)
|
||||
}
|
||||
|
||||
func (qb *ImageStore) Create(ctx context.Context, newObject *models.ImageCreateInput) error {
|
||||
func (qb *ImageStore) Create(ctx context.Context, newObject *models.Image, fileIDs []models.FileID) error {
|
||||
var r imageRow
|
||||
r.fromImage(*newObject.Image)
|
||||
r.fromImage(*newObject)
|
||||
|
||||
id, err := qb.tableMgr.insertID(ctx, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(newObject.FileIDs) > 0 {
|
||||
if len(fileIDs) > 0 {
|
||||
const firstPrimary = true
|
||||
if err := imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, newObject.FileIDs); err != nil {
|
||||
if err := imagesFilesTableMgr.insertJoins(ctx, id, firstPrimary, fileIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (qb *ImageStore) Create(ctx context.Context, newObject *models.ImageCreateI
|
||||
return fmt.Errorf("finding after create: %w", err)
|
||||
}
|
||||
|
||||
*newObject.Image = *updated
|
||||
*newObject = *updated
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -152,10 +152,7 @@ func Test_imageQueryBuilder_Create(t *testing.T) {
|
||||
}
|
||||
}
|
||||
s := tt.newObject
|
||||
if err := qb.Create(ctx, &models.ImageCreateInput{
|
||||
Image: &s,
|
||||
FileIDs: fileIDs,
|
||||
}); (err != nil) != tt.wantErr {
|
||||
if err := qb.Create(ctx, &s, fileIDs); (err != nil) != tt.wantErr {
|
||||
t.Errorf("imageQueryBuilder.Create() error = %v, wantErr = %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
|
||||
@@ -1177,10 +1177,7 @@ func createImages(ctx context.Context, n int) error {
|
||||
|
||||
image := makeImage(i)
|
||||
|
||||
err := qb.Create(ctx, &models.ImageCreateInput{
|
||||
Image: image,
|
||||
FileIDs: []models.FileID{f.ID},
|
||||
})
|
||||
err := qb.Create(ctx, image, []models.FileID{f.ID})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating image %v+: %s", image, err.Error())
|
||||
|
||||
@@ -890,9 +890,9 @@ func (qb *TagStore) queryTags(ctx context.Context, query string, args []interfac
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (qb *TagStore) queryTagPaths(ctx context.Context, query string, args []interface{}) (models.TagPaths, error) {
|
||||
func (qb *TagStore) queryTagPaths(ctx context.Context, query string, args []interface{}) ([]*models.TagPath, error) {
|
||||
const single = false
|
||||
var ret models.TagPaths
|
||||
var ret []*models.TagPath
|
||||
if err := qb.queryFunc(ctx, query, args, single, func(r *sqlx.Rows) error {
|
||||
var f tagPathRow
|
||||
if err := r.StructScan(&f); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user