Refactor controllers
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
module API
|
||||
class PlaylistsController < ApplicationController
|
||||
before_action :set_playlist, only: :show
|
||||
|
||||
def index
|
||||
@playlists = Playlist.all
|
||||
end
|
||||
|
||||
def show
|
||||
@playlist = Playlist.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -16,6 +17,10 @@ module API
|
||||
|
||||
private
|
||||
|
||||
def set_playlist
|
||||
@playlist = Playlist.find(params[:id])
|
||||
end
|
||||
|
||||
def playlist_params
|
||||
params.require(:playlist).permit :name
|
||||
end
|
||||
|
@@ -1,9 +1,16 @@
|
||||
module API
|
||||
class SoundsController < ApplicationController
|
||||
# FIXME: add some tests!
|
||||
before_action :set_sound, only: :show
|
||||
|
||||
def show
|
||||
sound = Sound.find(params[:id])
|
||||
send_file sound.path, type: sound.mime_type
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_sound
|
||||
@sound = Sound.find(params[:id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,10 +1,18 @@
|
||||
module API
|
||||
class TracksController < ApplicationController
|
||||
before_action :set_track, only: :show
|
||||
|
||||
def index
|
||||
@tracks = Track.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_track
|
||||
@track = Track.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user