diff --git a/internal/api/album.go b/internal/api/album.go index 0a532f9d8..ca28d2460 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -356,11 +356,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) { return } - p, _, err := query.PhotoSearch(form.PhotoSearch{ - Album: a.AlbumUID, - Count: 10000, - Offset: 0, - }) + p, err := query.AlbumPhotos(a, 10000) if err != nil { c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"error": txt.UcFirst(err.Error())}) diff --git a/internal/entity/album_fixtures.go b/internal/entity/album_fixtures.go index 0da3b8d9a..9460f43d6 100644 --- a/internal/entity/album_fixtures.go +++ b/internal/entity/album_fixtures.go @@ -74,6 +74,24 @@ var AlbumFixtures = AlbumMap{ UpdatedAt: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), DeletedAt: nil, }, + "april-1990": { + ID: 1000003, + CoverUID: "", + AlbumUID: "at1lxuqipogaaba1", + AlbumSlug: "april-1990", + AlbumType: TypeFolder, + AlbumTitle: "April 1990", + AlbumDescription: "Spring is the time of year when many things change.", + AlbumNotes: "Thunderstorms cause most of the severe spring weather.", + AlbumOrder: "oldest", + AlbumTemplate: "", + AlbumFilter: "path:\"1990/04\"", + AlbumFavorite: false, + Links: []Link{}, + CreatedAt: time.Date(2019, 7, 1, 0, 0, 0, 0, time.UTC), + UpdatedAt: time.Date(2020, 2, 1, 0, 0, 0, 0, time.UTC), + DeletedAt: nil, + }, } // CreateAlbumFixtures inserts known entities into the database for testing. diff --git a/internal/query/albums.go b/internal/query/albums.go index 357f76975..b915ae602 100644 --- a/internal/query/albums.go +++ b/internal/query/albums.go @@ -87,6 +87,18 @@ func AlbumCoverByUID(albumUID string) (file entity.File, err error) { return file, nil } +// AlbumPhotos returns up to count photos from an album. +func AlbumPhotos(a entity.Album, count int) (results PhotoResults, err error) { + results, _, err = PhotoSearch(form.PhotoSearch{ + Album: a.AlbumUID, + Filter: a.AlbumFilter, + Count: count, + Offset: 0, + }) + + return results, err +} + // AlbumSearch searches albums based on their name. func AlbumSearch(f form.AlbumSearch) (results []AlbumResult, err error) { if err := f.ParseQueryString(); err != nil { diff --git a/internal/query/albums_test.go b/internal/query/albums_test.go index c187794ac..8a835aa67 100644 --- a/internal/query/albums_test.go +++ b/internal/query/albums_test.go @@ -3,6 +3,7 @@ package query import ( "testing" + "github.com/photoprism/photoprism/internal/entity" form "github.com/photoprism/photoprism/internal/form" "github.com/stretchr/testify/assert" ) @@ -43,6 +44,21 @@ func TestAlbumThumbByUID(t *testing.T) { }) } +func TestAlbumPhotos(t *testing.T) { + t.Run("search with string", func(t *testing.T) { + results, err := AlbumPhotos(entity.AlbumFixtures.Get("april-1990"), 2) + + if err != nil { + t.Fatal(err) + } + + if len(results) < 2 { + t.Errorf("at least 2 results expected: %d", len(results)) + } + }) + +} + func TestAlbums(t *testing.T) { t.Run("search with string", func(t *testing.T) { query := form.NewAlbumSearch("chr")