From 45b78a73657ac172a7a04fab42f6cc25019be4a7 Mon Sep 17 00:00:00 2001 From: Wilco Date: Fri, 11 Oct 2024 21:01:19 +0200 Subject: [PATCH] Add filter for albums without photos that have tags (#432) * Add filter for albums without photos that have tags * Lint --- app/models/photo_album.rb | 4 ++++ app/resources/v1/photo_album_resource.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/models/photo_album.rb b/app/models/photo_album.rb index 9ca74bd0..5a01c4a0 100644 --- a/app/models/photo_album.rb +++ b/app/models/photo_album.rb @@ -10,6 +10,10 @@ class PhotoAlbum < ApplicationRecord scope :publicly_visible, (-> { where(publicly_visible: true) }) + scope :without_photo_tags, lambda { + where.not(id: Photo.joins(:tags).select(:photo_album_id).distinct) + } + def owners if group.present? group.active_users + [author] diff --git a/app/resources/v1/photo_album_resource.rb b/app/resources/v1/photo_album_resource.rb index 825023a8..a5a773bd 100644 --- a/app/resources/v1/photo_album_resource.rb +++ b/app/resources/v1/photo_album_resource.rb @@ -1,6 +1,8 @@ class V1::PhotoAlbumResource < V1::ApplicationResource attributes :title, :date, :publicly_visible + filter :without_photo_tags, apply: ->(records, _value, _options) { records.without_photo_tags } + has_many :photos has_one :author, always_include_linkage_data: true has_one :group, always_include_linkage_data: true