Skip to content

Commit

Permalink
Remove ImageCreateInput
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Sep 5, 2023
1 parent e6d865d commit c594f7d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 37 deletions.
5 changes: 1 addition & 4 deletions internal/autotag/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 1 addition & 4 deletions pkg/image/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/image/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/models/mocks/ImageReaderWriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions pkg/models/model_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,3 @@ func (i Image) DisplayName() string {

return strconv.Itoa(i.ID)
}

type ImageCreateInput struct {
*Image
FileIDs []FileID
}
2 changes: 1 addition & 1 deletion pkg/models/repository_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions pkg/sqlite/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/sqlite/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/sqlite/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit c594f7d

Please sign in to comment.