Skip to content

Commit

Permalink
Merge branch 'main' into iqs8-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loree authored Aug 10, 2024
2 parents 41fa687 + dc26a27 commit 3f381bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/playlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def remove_song

private

#Validate playlist belongs to user and Song belongs to user, or is public
def set_playlist_and_song
@playlist = current_user.playlists.find_by(id: params[:id])
@song = current_user.songs.find_by(id: params[:song_id]) || Song.where(privacy: 'public').find_by(id: params[:song_id])
Expand Down
14 changes: 13 additions & 1 deletion app/controllers/songs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
class SongsController < ApplicationController
before_action :authenticate_user!

# GET /songs
# GET /songs (all of the current user's songs)
def index
@songs = current_user.songs
render json: @songs
end

# GET /songs/# (get a single song)
def show
@song = current_user.songs.find_by(id: params[:id]) || Song.where(privacy: 'public').find_by(id: params[:id])

if @song.nil?
render json: { error: 'Song does not exist or is private/owned by someone else' }, status: :not_found
return
end

render json: @song, status: :ok
end

# POST /songs
def create
@song = current_user.songs.build(song_params)
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end
end

resources :songs, only: %i[index create]
resources :songs

get 'up' => 'rails/health#show', as: :rails_health_check
end

0 comments on commit 3f381bf

Please sign in to comment.