Implement playlists/show in API
This commit is contained in:
parent
35be3e21b6
commit
b3cfa88bb9
@ -4,6 +4,10 @@ module API
|
||||
@playlists = Playlist.all
|
||||
end
|
||||
|
||||
def show
|
||||
@playlist = Playlist.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@playlist = current_user.playlists.build playlist_params
|
||||
@playlist.save
|
||||
|
4
app/views/api/playlists/show.rabl
Normal file
4
app/views/api/playlists/show.rabl
Normal file
@ -0,0 +1,4 @@
|
||||
object @playlist
|
||||
|
||||
attribute :id
|
||||
attribute :name
|
@ -4,7 +4,7 @@ Rails.application.routes.draw do
|
||||
namespace :api do
|
||||
get '/ping', to: 'application#ping'
|
||||
match '*all', to: 'application#cor_preflight', via: :options
|
||||
resources :playlists, only: %i[index create]
|
||||
resources :playlists, only: %i[index show create]
|
||||
resources :sessions, only: :create
|
||||
resources :sounds, only: :show
|
||||
resources :tracks, only: :index
|
||||
|
@ -15,6 +15,16 @@ describe 'API playlists' do
|
||||
]
|
||||
end
|
||||
|
||||
it 'shows a playlist' do
|
||||
playlist = create :playlist
|
||||
get api_playlist_path playlist, format: :json
|
||||
|
||||
expect(json).to match(
|
||||
id: playlist.id,
|
||||
name: playlist.name
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates playlist' do
|
||||
playlist = attributes_for :playlist
|
||||
post api_playlists_path,
|
||||
|
Loading…
x
Reference in New Issue
Block a user