work
This commit is contained in:
parent
8d7ec6d9e7
commit
a6ebbb3c7e
|
|
@ -2,6 +2,7 @@ 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
|
||||
|
||||
|
|
@ -44,15 +45,26 @@ class ApiMusicSessionsController < ApiController
|
|||
end
|
||||
|
||||
def show
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
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
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
|
||||
unless @music_session.can_delete? current_user
|
||||
raise ActiveRecord::RecordNotound
|
||||
|
|
@ -94,5 +106,8 @@ class ApiMusicSessionsController < ApiController
|
|||
respond_with @connection, responder: ApiResponder
|
||||
end
|
||||
|
||||
def lookup_session
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ SampleApp::Application.routes.draw do
|
|||
match '/participants/:id' => 'api_music_sessions#participant_show', :via => :get, :as => 'api_session_participant_detail'
|
||||
match '/participants/:id' => 'api_music_sessions#participant_delete', :via => :delete
|
||||
match '/sessions/:id' => 'api_music_sessions#show', :via => :get, :as => 'api_session_detail'
|
||||
match '/sessions/:id' => 'api_music_sessions#update', :via => :put
|
||||
match '/sessions/:id' => 'api_music_sessions#delete', :via => :delete
|
||||
match '/sessions' => 'api_music_sessions#index', :via => :get
|
||||
match '/sessions' => 'api_music_sessions#create', :via => :post
|
||||
|
|
|
|||
|
|
@ -59,6 +59,25 @@ class MusicSessionManager < BaseManager
|
|||
return return_value
|
||||
end
|
||||
|
||||
def update(music_session, description, genres, musician_access, approval_required, fan_chat, fan_access)
|
||||
ActiveRecord::Base.transaction do
|
||||
music_session.description = description
|
||||
music_session.musician_access = musician_access
|
||||
music_session.approval_required = approval_required
|
||||
music_session.fan_chat = fan_chat
|
||||
music_session.fan_access = fan_access
|
||||
# Do I have to do this the way he did above? Not sure. Probably yes.
|
||||
genre_array = []
|
||||
unless genres.nil?
|
||||
genres.each do |genre_id|
|
||||
loaded_genre = Genre.find(genre_id)
|
||||
genre_array << loaded_genre
|
||||
end
|
||||
end
|
||||
music_session.genres = genre_array
|
||||
end
|
||||
end
|
||||
|
||||
def participant_create(user, music_session_id, client_id, as_musician, tracks)
|
||||
connection = nil
|
||||
ActiveRecord::Base.transaction do
|
||||
|
|
|
|||
Loading…
Reference in New Issue