Search albums by country (#905)

This commit is contained in:
Krassimir Valev 2021-01-16 12:48:43 +01:00 committed by GitHub
parent 67e655f6d0
commit a90ee62cd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -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),

View file

@ -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
}
}

View file

@ -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")