added ImageMetadataAll

This commit is contained in:
Philipp Häfelfinger 2019-03-23 23:55:55 +01:00
parent 0d9579534d
commit c4e33598e9
4 changed files with 80 additions and 0 deletions

View File

@ -39,6 +39,7 @@ type ImageMetadataProvider interface {
ImageMetadata(fullImagePath string) (ImageMetaData, error)
ImageMetadataToUpload() ([]ImageMetaData, error)
ImageMetadataToDelete() ([]ImageMetaData, error)
ImageMetadataAll() ([]ImageMetaData, error)
SaveImageMetadata(m ImageMetaData) error
SavePiwigoIdAndUpdateUploadFlag(md5Sum string, piwigoId int) error
}
@ -99,6 +100,35 @@ func (d *localDataStore) ImageMetadata(fullImagePath string) (ImageMetaData, err
return img, err
}
func (d *localDataStore) ImageMetadataAll() ([]ImageMetaData, error) {
logrus.Tracef("Query all image metadata that represent files on the disk")
db, err := d.openDatabase()
if err != nil {
return nil, err
}
defer db.Close()
rows, err := db.Query("SELECT imageId, piwigoId, fullImagePath, fileName, md5sum, lastChanged, categoryPath, categoryId, uploadRequired, deleteRequired FROM image")
if err != nil {
return nil, err
}
defer rows.Close()
images := []ImageMetaData{}
for rows.Next() {
img := &ImageMetaData{}
err = ReadImageMetadataFromRow(rows, img)
if err != nil {
return nil, err
}
images = append(images, *img)
}
err = rows.Err()
return images, err
}
func (d *localDataStore) ImageMetadataToDelete() ([]ImageMetaData, error) {
logrus.Tracef("Query all image metadata that represent files queued to delete")

View File

@ -47,6 +47,21 @@ func (mr *MockImageMetadataProviderMockRecorder) ImageMetadata(arg0 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageMetadata", reflect.TypeOf((*MockImageMetadataProvider)(nil).ImageMetadata), arg0)
}
// ImageMetadataAll mocks base method
func (m *MockImageMetadataProvider) ImageMetadataAll() ([]ImageMetaData, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ImageMetadataAll")
ret0, _ := ret[0].([]ImageMetaData)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ImageMetadataAll indicates an expected call of ImageMetadataAll
func (mr *MockImageMetadataProviderMockRecorder) ImageMetadataAll() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImageMetadataAll", reflect.TypeOf((*MockImageMetadataProvider)(nil).ImageMetadataAll))
}
// ImageMetadataToDelete mocks base method
func (m *MockImageMetadataProvider) ImageMetadataToDelete() ([]ImageMetaData, error) {
m.ctrl.T.Helper()

View File

@ -44,6 +44,37 @@ func Test_save_and_load_metadata(t *testing.T) {
EnsureMetadataAreEqual("update", img, imgLoad, t)
}
func Test_save_and_query_for_all_entries(t *testing.T) {
if !dbinitOk {
t.Skip("Skipping test as TestDataStoreInitialize failed!")
}
dataStore := setupDatabase(t)
defer cleanupDatabase(t)
img1 := getExampleImageMetadata("blah/foo/bar.jpg")
img2 := getExampleImageMetadata("blah/foo/bar2.jpg")
img2.DeleteRequired = true
saveImageShouldNotFail("allimages", dataStore, img1, t)
img1.ImageId = 1
saveImageShouldNotFail("allimages", dataStore, img2, t)
img2.ImageId = 2
images, err := dataStore.ImageMetadataAll()
if err != nil {
t.Fatalf("Could not query images to upload! %s", err)
}
if len(images) != 2 {
t.Fatalf("Got incorrect number of images (%d). Expected two.", len(images))
}
imgLoad := images[0]
EnsureMetadataAreEqual("allimages", img1, imgLoad, t)
}
func Test_save_and_query_for_upload_records(t *testing.T) {
if !dbinitOk {
t.Skip("Skipping test as TestDataStoreInitialize failed!")

View File

@ -429,6 +429,10 @@ func (s *testStore) ImageMetadata(fullImagePath string) (ImageMetaData, error) {
return metadata, nil
}
func (d *testStore) ImageMetadataAll() ([]ImageMetaData, error) {
return []ImageMetaData{}, nil
}
func (s *testStore) SaveImageMetadata(m ImageMetaData) error {
s.savedMetadata[m.FullImagePath] = m
return nil