From c594f7da5df68c9daa4791b8737a7c92034c0293 Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:29:23 +0200 Subject: [PATCH] Remove ImageCreateInput --- internal/autotag/integration_test.go | 5 +---- pkg/image/import.go | 5 +---- pkg/image/scan.go | 7 ++----- pkg/models/mocks/ImageReaderWriter.go | 10 +++++----- pkg/models/model_image.go | 5 ----- pkg/models/repository_image.go | 2 +- pkg/sqlite/image.go | 10 +++++----- pkg/sqlite/image_test.go | 5 +---- pkg/sqlite/setup_test.go | 5 +---- 9 files changed, 17 insertions(+), 37 deletions(-) diff --git a/internal/autotag/integration_test.go b/internal/autotag/integration_test.go index 774a7738bab..84ae016987c 100644 --- a/internal/autotag/integration_test.go +++ b/internal/autotag/integration_test.go @@ -362,10 +362,7 @@ func makeImage(expectedResult bool) *models.Image { } func createImage(ctx context.Context, w models.ImageWriter, o *models.Image, f *models.ImageFile) error { - err := w.Create(ctx, &models.ImageCreateInput{ - Image: o, - FileIDs: []models.FileID{f.ID}, - }) + err := w.Create(ctx, o, []models.FileID{f.ID}) if err != nil { return fmt.Errorf("Failed to create image with path '%s': %s", f.Path, err.Error()) diff --git a/pkg/image/import.go b/pkg/image/import.go index 208b535759b..d5ad591a997 100644 --- a/pkg/image/import.go +++ b/pkg/image/import.go @@ -331,10 +331,7 @@ func (i *Importer) Create(ctx context.Context) (*int, error) { fileIDs = append(fileIDs, f.Base().ID) } - err := i.ReaderWriter.Create(ctx, &models.ImageCreateInput{ - Image: &i.image, - FileIDs: fileIDs, - }) + err := i.ReaderWriter.Create(ctx, &i.image, fileIDs) if err != nil { return nil, fmt.Errorf("error creating image: %v", err) } diff --git a/pkg/image/scan.go b/pkg/image/scan.go index 4e75e8d0c7b..5c9cbe8e08a 100644 --- a/pkg/image/scan.go +++ b/pkg/image/scan.go @@ -26,7 +26,7 @@ type ScanCreatorUpdater interface { GetFiles(ctx context.Context, relatedID int) ([]models.File, error) GetGalleryIDs(ctx context.Context, relatedID int) ([]int, error) - Create(ctx context.Context, newImage *models.ImageCreateInput) error + Create(ctx context.Context, newImage *models.Image, fileIDs []models.FileID) error UpdatePartial(ctx context.Context, id int, updatedImage models.ImagePartial) (*models.Image, error) AddFileID(ctx context.Context, id int, fileID models.FileID) error } @@ -123,10 +123,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models. logger.Infof("Adding %s to gallery %s", f.Base().Path, g.Path) } - if err := h.CreatorUpdater.Create(ctx, &models.ImageCreateInput{ - Image: &newImage, - FileIDs: []models.FileID{imageFile.ID}, - }); err != nil { + if err := h.CreatorUpdater.Create(ctx, &newImage, []models.FileID{imageFile.ID}); err != nil { return fmt.Errorf("creating new image: %w", err) } diff --git a/pkg/models/mocks/ImageReaderWriter.go b/pkg/models/mocks/ImageReaderWriter.go index 4924fd51d11..a3ec6987792 100644 --- a/pkg/models/mocks/ImageReaderWriter.go +++ b/pkg/models/mocks/ImageReaderWriter.go @@ -114,13 +114,13 @@ func (_m *ImageReaderWriter) CountByGalleryID(ctx context.Context, galleryID int return r0, r1 } -// Create provides a mock function with given fields: ctx, newImage -func (_m *ImageReaderWriter) Create(ctx context.Context, newImage *models.ImageCreateInput) error { - ret := _m.Called(ctx, newImage) +// Create provides a mock function with given fields: ctx, newImage, fileIDs +func (_m *ImageReaderWriter) Create(ctx context.Context, newImage *models.Image, fileIDs []models.FileID) error { + ret := _m.Called(ctx, newImage, fileIDs) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *models.ImageCreateInput) error); ok { - r0 = rf(ctx, newImage) + if rf, ok := ret.Get(0).(func(context.Context, *models.Image, []models.FileID) error); ok { + r0 = rf(ctx, newImage, fileIDs) } else { r0 = ret.Error(0) } diff --git a/pkg/models/model_image.go b/pkg/models/model_image.go index dee7919ea21..797f638ad35 100644 --- a/pkg/models/model_image.go +++ b/pkg/models/model_image.go @@ -135,8 +135,3 @@ func (i Image) DisplayName() string { return strconv.Itoa(i.ID) } - -type ImageCreateInput struct { - *Image - FileIDs []FileID -} diff --git a/pkg/models/repository_image.go b/pkg/models/repository_image.go index 5b191b2ab8c..b6eb895a06b 100644 --- a/pkg/models/repository_image.go +++ b/pkg/models/repository_image.go @@ -36,7 +36,7 @@ type ImageCounter interface { // ImageCreator provides methods to create images. type ImageCreator interface { - Create(ctx context.Context, newImage *ImageCreateInput) error + Create(ctx context.Context, newImage *Image, fileIDs []FileID) error } // ImageUpdater provides methods to update images. diff --git a/pkg/sqlite/image.go b/pkg/sqlite/image.go index 35982642695..0258ce537eb 100644 --- a/pkg/sqlite/image.go +++ b/pkg/sqlite/image.go @@ -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 } diff --git a/pkg/sqlite/image_test.go b/pkg/sqlite/image_test.go index 900c0b79456..621b72c64cc 100644 --- a/pkg/sqlite/image_test.go +++ b/pkg/sqlite/image_test.go @@ -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) } diff --git a/pkg/sqlite/setup_test.go b/pkg/sqlite/setup_test.go index 737a28e7230..04236b3ac1c 100644 --- a/pkg/sqlite/setup_test.go +++ b/pkg/sqlite/setup_test.go @@ -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())