VRFS-1678 added music session update feature
This commit is contained in:
parent
00d06fe6f2
commit
5685e2f0e8
|
|
@ -178,6 +178,18 @@ module JamRuby
|
|||
ms
|
||||
end
|
||||
|
||||
def self.update user, options
|
||||
music_session = MusicSession.find(options[:id])
|
||||
if music_session.creator == current_user
|
||||
Notification.send_scheduled_session_cancelled music_session
|
||||
music_session.destroy
|
||||
|
||||
respond_with responder: ApiResponder, :status => 204
|
||||
else
|
||||
render :json => { :message => ValidationMessages::PERMISSION_VALIDATION_ERROR }, :status => 404
|
||||
end
|
||||
end
|
||||
|
||||
def unique_users
|
||||
User
|
||||
.joins(:music_session_user_histories)
|
||||
|
|
|
|||
|
|
@ -164,6 +164,42 @@ class ApiMusicSessionsController < ApiController
|
|||
end
|
||||
end
|
||||
|
||||
def session_update
|
||||
begin
|
||||
@music_session = MusicSession.find(params[:id])
|
||||
if @music_session.creator == current_user
|
||||
band = Band.find(options[:band]) unless params[:band_id].nil?
|
||||
|
||||
@music_session.name = params[:name] unless params[:name].nil?
|
||||
@music_session.description = params[:description] unless params[:description].nil?
|
||||
@music_session.musician_access = params[:musician_access] unless params[:musician_access].nil?
|
||||
@music_session.approval_required = params[:approval_required] unless params[:approval_required].nil?
|
||||
@music_session.fan_chat = params[:fan_chat] unless params[:fan_chat].nil?
|
||||
@music_session.fan_access = params[:fan_access] unless params[:fan_access].nil?
|
||||
@music_session.genre = Genre.find_by_id(params[:genres][0]) if params[:genres] && params[:genres].length > 0
|
||||
@music_session.legal_policy = params[:legal_policy] unless params[:legal_policy].nil?
|
||||
@music_session.language = params[:language] unless params[:language].nil?
|
||||
@music_session.scheduled_start = params[:start] unless params[:start].nil?
|
||||
@music_session.timezone = params[:timezone] unless params[:timezone].nil?
|
||||
@music_session.recurring_mode = params[:reoccurrence] unless params[:reoccurrence].nil?
|
||||
@music_session.band = band unless band.nil?
|
||||
@music_session.save
|
||||
|
||||
if @music_session.errors.any?
|
||||
response.status = :unprocessable_entity
|
||||
respond_with @music_session
|
||||
else
|
||||
respond_with @music_session, responder: ApiResponder, :location => api_session_history_detail_url(@music_session)
|
||||
end
|
||||
else
|
||||
render :json => { :message => ValidationMessages::PERMISSION_VALIDATION_ERROR }, :status => 404
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render :json => { :message => ValidationMessages::SESSION_NOT_FOUND }, :status => 404
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
begin
|
||||
music_session = MusicSession.find(params[:id])
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ SampleApp::Application.routes.draw do
|
|||
match '/sessions/scheduled' => 'api_music_sessions#scheduled', :via => :get
|
||||
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#session_update', :via => :post
|
||||
match '/sessions/:id' => 'api_music_sessions#destroy', :via => :delete
|
||||
match '/sessions' => 'api_music_sessions#index', :via => :get
|
||||
match '/sessions' => 'api_music_sessions#create', :via => :post
|
||||
|
|
|
|||
|
|
@ -106,5 +106,29 @@ describe "Scheduled Music Session API ", :type => :api do
|
|||
last_response.status.should eql(404)
|
||||
JSON.parse(last_response.body)["message"].should == ValidationMessages::PERMISSION_VALIDATION_ERROR
|
||||
end
|
||||
|
||||
it "should update music session" do
|
||||
user2 = FactoryGirl.create(:user)
|
||||
login(user)
|
||||
|
||||
post '/api/sessions.json', defopts.merge({start: Time.now + 3.hours}).to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
music_session = JSON.parse(last_response.body)
|
||||
|
||||
post "/api/sessions/#{music_session["id"]}.json", {:name => "changed name"}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(201)
|
||||
changed_session = JSON.parse(last_response.body)
|
||||
changed_session["name"].should == "changed name"
|
||||
|
||||
post "/api/sessions/#{music_session["id"]}.json", {:genres => ["fake genres"]}.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
last_response.status.should eql(422)
|
||||
changed_session = JSON.parse(last_response.body)
|
||||
changed_session["errors"].should == {"genre"=>["can't be blank"]}
|
||||
|
||||
login(user2)
|
||||
post "/api/sessions/#{music_session["id"]}.json", {:name => "changed name"}.to_json
|
||||
last_response.status.should eql(404)
|
||||
JSON.parse(last_response.body)["message"].should == ValidationMessages::PERMISSION_VALIDATION_ERROR
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue