82 lines
2.2 KiB
Ruby
82 lines
2.2 KiB
Ruby
class ApiBandsController < ApplicationController
|
|
|
|
before_filter :api_signed_in_user, :only => [:index, :show, :create, :update,
|
|
:following_create, :following_destroy]
|
|
|
|
respond_to :json
|
|
|
|
def index
|
|
@bands = Band.paginate(page: params[:page])
|
|
end
|
|
|
|
def show
|
|
@band = Band.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@band = Band.save(params[:id],
|
|
params[:name],
|
|
params[:website],
|
|
params[:biography],
|
|
params[:city],
|
|
params[:state],
|
|
params[:country],
|
|
params[:genres])
|
|
|
|
respond_with @band, responder: ApiResponder, :location => api_band_detail_url(@band)
|
|
=begin
|
|
# check for errors
|
|
if @band.errors.nil? || @band.errors.size == 0
|
|
respond_with @band, responder: ApiResponder, :location => api_band_detail_url(@band)
|
|
|
|
else
|
|
raise ActiveRecord::Rollback
|
|
response.status = :unprocessable_entity
|
|
respond_with @band
|
|
end
|
|
=end
|
|
end
|
|
|
|
def update
|
|
@band = Band.save(params[:id],
|
|
params[:name],
|
|
params[:website],
|
|
params[:biography],
|
|
params[:city],
|
|
params[:state],
|
|
params[:country],
|
|
params[:genres])
|
|
|
|
# check for errors
|
|
if @band.errors.nil? || @band.errors.size == 0
|
|
respond_with @band, responder: ApiResponder, :status => :ok
|
|
|
|
else
|
|
raise ActiveRecord::Rollback
|
|
response.status = :unprocessable_entity
|
|
respond_with @band
|
|
end
|
|
end
|
|
|
|
###################### FOLLOWERS ########################
|
|
def follower_index
|
|
# NOTE: follower_index.rabl template references the followers property
|
|
@band = Band.find(params[:id])
|
|
end
|
|
|
|
###################### RECORDINGS #######################
|
|
def recording_index
|
|
@recordings = Recording.paginate(page: params[:page])
|
|
end
|
|
|
|
def recording_create
|
|
Recording.save(params[:recording_id],
|
|
params[:public],
|
|
params[:description],
|
|
params[:id],
|
|
true)
|
|
end
|
|
|
|
def recording_destroy
|
|
end
|
|
end |