class ApiMusicSessionsController < ApiController # have to be signed in currently to see this screen before_filter :api_signed_in_user before_filter :lookup_session, only: [:show, :update, :delete] respond_to :json def index # params[:genres] is either nil, meaning "everything", or it's an array of genre ids # params[:friends_only] does the obvious. # params[:my_bands_only] also does the obvious. # Importantly, friends and my_bands are ORed not ANDed. So, if you specify both as true, you'll get more results, not fewer. @music_sessions = MusicSession.index(current_user, params[:genres], params[:friends_only], params[:my_bands_only]) end def create client_id = params[:client_id] band = Band.find(params[:band]) unless params[:band].nil? if client_id.nil? raise JamArgumentError, "client_id must be specified" end @music_session = MusicSessionManager.new.create( current_user, client_id, params[:description], params[:musician_access], params[:approval_required], params[:fan_chat], params[:fan_access], band, params[:genres], params[:tracks], params[:legal_terms]) if @music_session.errors.any? # we have to do this because api_session_detail_url will fail with a bad @music_session response.status = :unprocessable_entity respond_with @music_session else respond_with @music_session, responder: ApiResponder, :location => api_session_detail_url(@music_session) end end def show unless @music_session.can_see? current_user raise ActiveRecord::RecordNotFound end end def update @music_session = MusicSessionManager.new.update( @music_session, params[:music_session][:description], params[:music_session][:genres], params[:music_session][:musician_access], params[:music_session][:approval_required], params[:music_session][:fan_chat], params[:music_session][:fan_access]) #FIXME: What to do if validations fail? respond_with @music_session, responder: ApiResponder, :location => api_session_detail_url(@music_session) end def delete unless @music_session.can_delete? current_user raise ActiveRecord::RecordNotound end @music_session.destroy # required to make 'tire' integration work respond_with @music_session, responder: ApiResponder end def participant_show @connection = Connection.find_by_client_id(params[:id]) end def participant_create @connection = MusicSessionManager.new.participant_create( current_user, params[:id], params[:client_id], params[:as_musician], params[:tracks]) if @connection.errors.any? response.status = :unprocessable_entity respond_with @connection else respond_with @connection, responder: ApiResponder, :location => api_session_participant_detail_url(@connection.client_id) end end def participant_delete client_id = params[:id] @connection = Connection.find_by_client_id!(client_id) music_session = MusicSession.find(@connection.music_session_id) MusicSessionManager.new.participant_delete(current_user, @connection, music_session) respond_with @connection, responder: ApiResponder end def lookup_session @music_session = MusicSession.find(params[:id]) end end