68 lines
1.7 KiB
Ruby
68 lines
1.7 KiB
Ruby
class ApiBandsController < ApplicationController
|
|
|
|
before_filter :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)
|
|
|
|
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)
|
|
|
|
# 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
|
|
|
|
# FOLLOWINGS
|
|
def following_create
|
|
@follower = BandFollower.new()
|
|
@follower.user_id = params[:follower_id]
|
|
@follower.follower_id = params[:id]
|
|
@follower.save
|
|
@user = User.find(params[:follower_id])
|
|
respond_with @user, responder: ApiResponder, :location => api_following_index_url(@user)
|
|
end
|
|
|
|
def following_destroy
|
|
JamRuby::BandFollower.delete_all "(user_id = '#{params[:user_id]}' AND band_id = '#{params[:id]}')"
|
|
respond_with responder: ApiResponder
|
|
end
|
|
|
|
end |