diff --git a/internal/entity/album_fixtures.go b/internal/entity/album_fixtures.go index 631f8481a..91ec590b1 100644 --- a/internal/entity/album_fixtures.go +++ b/internal/entity/album_fixtures.go @@ -66,6 +66,7 @@ var AlbumFixtures = AlbumMap{ AlbumNotes: "", AlbumOrder: "oldest", AlbumTemplate: "", + AlbumCountry: "de", AlbumFavorite: false, CreatedAt: time.Date(2019, 7, 1, 0, 0, 0, 0, time.UTC), UpdatedAt: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), diff --git a/internal/query/albums.go b/internal/query/albums.go index 7dbfbacd7..3b28848a6 100644 --- a/internal/query/albums.go +++ b/internal/query/albums.go @@ -143,6 +143,10 @@ func AlbumSearch(f form.AlbumSearch) (results AlbumResults, err error) { s = s.Where("albums.album_location IN (?)", strings.Split(f.Location, Or)) } + if f.Country != "" { + s = s.Where("albums.album_country IN (?)", strings.Split(f.Country, Or)) + } + if f.Favorite { s = s.Where("albums.album_favorite = 1") } @@ -199,7 +203,7 @@ func UpdateAlbumDates() error { func UpdateMissingAlbumEntries() error { switch DbDialect() { default: - return UnscopedDb().Exec(`UPDATE photos_albums SET missing = 1 WHERE photo_uid IN + return UnscopedDb().Exec(`UPDATE photos_albums SET missing = 1 WHERE photo_uid IN (SELECT photo_uid FROM photos WHERE deleted_at IS NOT NULL OR photo_quality < 0)`).Error } } diff --git a/internal/query/albums_test.go b/internal/query/albums_test.go index 8e2b7b920..30a509a3e 100644 --- a/internal/query/albums_test.go +++ b/internal/query/albums_test.go @@ -98,6 +98,17 @@ func TestAlbumSearch(t *testing.T) { assert.Equal(t, "Holiday2030", result[0].AlbumTitle) }) + t.Run("search with country", func(t *testing.T) { + query := form.NewAlbumSearch("country:de") + result, err := AlbumSearch(query) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, "Berlin 2019", result[0].AlbumTitle) + }) + t.Run("favorites true", func(t *testing.T) { query := form.NewAlbumSearch("favorite:true count:10000")