From 1fe6f7806c3ef854d793b680783a13f3613dc3b3 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Martinez Date: Sat, 11 May 2024 22:09:56 -0400 Subject: [PATCH] queries for albums --- app/controllers/playlists_controller.rb | 10 ++++++-- app/controllers/users_controller.rb | 31 ++++--------------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/app/controllers/playlists_controller.rb b/app/controllers/playlists_controller.rb index a122184..90a0b9a 100644 --- a/app/controllers/playlists_controller.rb +++ b/app/controllers/playlists_controller.rb @@ -43,7 +43,7 @@ def show def edit @tab = params[:tab] || "basic-info-tab" - @playlist = current_user.playlists.friendly.find(params[:id]) + @playlist = find_playlist @playlist.enable_label = @playlist.label_id.present? end @@ -66,7 +66,7 @@ def create def update @tab = params[:tab] || "basic-info-tab" - @playlist = current_user.playlists.friendly.find(params[:id]) + @playlist = find_playlist @playlist.assign_attributes(playlist_params) @@ -115,4 +115,10 @@ def sort render "update" end + + def find_playlist + Playlist + .where(user_id: current_user.id).or(Playlist.where(label_id: current_user.id)) + .friendly.find(params[:id]) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c71e3a8..174f63c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -59,7 +59,8 @@ def playlists_filter def playlists @title = "Playlists" @section = "playlists" - @collection = @user.playlists + @collection = Playlist + .where(user_id: @user.id).or(Playlist.where(label_id: @user.id)) .where.not(playlist_type: ["album", "ep"]) .with_attached_cover .includes(user: {avatar_attachment: :blob}) @@ -69,33 +70,9 @@ def playlists @collection = @collection.where(private: false) end - @collection.or(Playlist.where(label_id: @user.id)) if @user.label? - @collection = @collection.references(:tracks) .page(params[:page]) - #@collection = @collection - #.where( - # playlists: {user_id: @user.id}, - # tracks: {user_id: @user.id} - #) if current_user.present? - - #.or( - # @user.playlists - # .where( - # playlists: {private: true}, - # tracks: {private: true, user_id: @user.id} - # ) - #) - #.or( - # @user.playlists - # .where.not( - # playlists: {user_id: @user.id}, - # tracks: {user_id: @user.id} - # ) - # .where(tracks: {private: true}) - #) - @as = :playlist @section = "playlists/playlist_item" render "show" @@ -112,9 +89,9 @@ def reposts def albums @title = "Albums" @section = "albums" - @collection = @user.playlists + @collection = Playlist + .where(user_id: @user.id).or(Playlist.where(label_id: @user.id)) .where(playlist_type: ["album", "ep"]) - .where(user_id: @user.id) .with_attached_cover .includes(user: {avatar_attachment: :blob}) .includes(tracks: {cover_attachment: :blob})