Skip to content

Commit

Permalink
queries for albums
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed May 12, 2024
1 parent c6579f3 commit 1fe6f78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
10 changes: 8 additions & 2 deletions app/controllers/playlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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
31 changes: 4 additions & 27 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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"
Expand All @@ -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})
Expand Down

0 comments on commit 1fe6f78

Please sign in to comment.