jam-cloud/app/controllers/api_claimed_recordings_cont...

45 lines
1.3 KiB
Ruby

class ApiClaimedRecordingsController < ApiController
before_filter :api_signed_in_user
before_filter :look_up_claimed_recording, :only => [ :show, :update, :delete ]
respond_to :json
def index
@claimed_recordings = ClaimedRecording.where(:user_id => current_user.id).order("created_at DESC").paginate(page: params[:page])
end
def show
@claimed_recording
end
def update
begin
@claimed_recording.update_fields(current_user, params)
respond_with responder: ApiResponder, :status => 204
rescue
render :json => { :message => "claimed_recording could not be updated" }, :status => 403
end
end
def delete
begin
@claimed_recording.discard(current_user)
render :json => {}, :status => 204
# respond_with responder: ApiResponder, :status => 204
rescue
render :json => { :message => "claimed_recording could not be deleted" }, :status => 403
end
end
private
def look_up_claimed_recording
@claimed_recording = ClaimedRecording.find(params[:id])
if @claimed_recording.nil? || @claimed_recording.user_id != current_user.id
render :json => { :message => "claimed_recording not found" }, :status => 404
end
end
end