Albums: Use most recent photo with best quality as cover

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-27 14:25:04 +02:00
parent 95cc4ec43f
commit d5490c0364

View file

@ -39,11 +39,11 @@ func (q *Query) AlbumByUUID(albumUUID string) (album entity.Album, err error) {
// AlbumThumbByUUID returns a album preview file based on the uuid.
func (q *Query) AlbumThumbByUUID(albumUUID string) (file entity.File, err error) {
// q.db.LogMode(true)
if err := q.db.Where("files.file_primary AND files.deleted_at IS NULL").
if err := q.db.Where("files.file_primary = 1 AND files.deleted_at IS NULL").
Joins("JOIN albums ON albums.album_uuid = ?", albumUUID).
Joins("JOIN photos_albums pa ON pa.album_uuid = albums.album_uuid AND pa.photo_uuid = files.photo_uuid").
Joins("JOIN photos ON photos.id = files.photo_id AND photos.deleted_at IS NULL").
Order("photos.photo_quality DESC, photos.taken_at DESC").
First(&file).Error; err != nil {
return file, err
}