From b5a031592ee5b9dfe0625720924ba8e775bb96c6 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 6 Jan 2013 15:47:56 -0500 Subject: [PATCH] VRFS-80 session history --- app/controllers/api_users_controller.rb | 13 ++++++++++--- app/views/api_music_sessions/show.rabl | 2 +- app/views/api_users/session_history_index.rabl | 7 +++++++ app/views/api_users/session_user_history_index.rabl | 3 +++ config/routes.rb | 5 ++++- lib/managers/music_session_manager.rb | 9 ++++++++- spec/requests/music_sessions_api_spec.rb | 12 +++++++++++- 7 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 app/views/api_users/session_history_index.rabl create mode 100644 app/views/api_users/session_user_history_index.rabl diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index e93c78765..6e6239f72 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -1,7 +1,7 @@ class ApiUsersController < ApiController before_filter :api_signed_in_user, :except => [:create, :signup_confirm, :auth_session_create] - before_filter :auth_user, :only => [:session_settings_show, :update, :delete, + before_filter :auth_user, :only => [:session_settings_show, :session_history_index, :session_user_history_index, :update, :delete, :like_create, :like_destroy, # likes :following_create, :following_destroy, # followings :recording_update, :recording_destroy, # recordings @@ -141,6 +141,15 @@ class ApiUsersController < ApiController respond_with @user.my_session_settings, responder: ApiResponder end + ###################### SESSION HISTORY ################### + def session_history_index + @session_history = @user.session_history(params[:id], params[:band_id], params[:genre]) + end + + def session_user_history_index + @session_user_history = @user.session_user_history(params[:id], params[:session_id]) + end + ###################### BANDS ######################## def band_index @bands = User.band_index(params[:id]) @@ -260,7 +269,6 @@ class ApiUsersController < ApiController nil, params[:message]) - @user = current_user respond_with @friend_request, responder: ApiResponder, :status => 201, :location => api_friend_request_detail_url(@user, @friend_request) end @@ -289,7 +297,6 @@ class ApiUsersController < ApiController ##################### BAND INVITATIONS ################## def band_invitation_index - @user = current_user @invitations = @user.received_band_invitations respond_with @invitations, responder: ApiResponder, :status => 200 end diff --git a/app/views/api_music_sessions/show.rabl b/app/views/api_music_sessions/show.rabl index 38c8affb8..21658ab53 100644 --- a/app/views/api_music_sessions/show.rabl +++ b/app/views/api_music_sessions/show.rabl @@ -1,6 +1,6 @@ object @music_session -attributes :id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id +attributes :id, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id node :genres do |item| item.genres.map(&:id) diff --git a/app/views/api_users/session_history_index.rabl b/app/views/api_users/session_history_index.rabl new file mode 100644 index 000000000..4ba35abc2 --- /dev/null +++ b/app/views/api_users/session_history_index.rabl @@ -0,0 +1,7 @@ +object @session_history + +attributes :music_session_id, :user_id, :description, :band_id, :genres + +child :music_session_user_histories => :participants do + attributes :client_id, :user_id +end \ No newline at end of file diff --git a/app/views/api_users/session_user_history_index.rabl b/app/views/api_users/session_user_history_index.rabl new file mode 100644 index 000000000..73b769c16 --- /dev/null +++ b/app/views/api_users/session_user_history_index.rabl @@ -0,0 +1,3 @@ +object @session_user_history + +attributes :music_session_id, :user_id, :client_id \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d891c8ec0..310dcb3e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,6 +76,10 @@ SampleApp::Application.routes.draw do # session settings match '/users/:id/session_settings' => 'api_users#session_settings_show', :via => :get + # session history + match '/users/:id/session_history' => 'api_users#session_history_index', :via => :get + match '/users/:id/session_history/:session_id/users' => 'api_users#session_user_history_index', :via => :get + # user bands match '/users/:id/bands' => 'api_users#band_index', :via => :get @@ -123,7 +127,6 @@ SampleApp::Application.routes.draw do match '/users/:id/recordings' => 'api_users#recording_create', :via => :post match '/users/:id/recordings/:recording_id' => 'api_users#recording_update', :via => :post match '/users/:id/recordings/:recording_id' => 'api_users#recording_destroy', :via => :delete - # bands match '/bands' => 'api_bands#index', :via => :get diff --git a/lib/managers/music_session_manager.rb b/lib/managers/music_session_manager.rb index cf6cbe04f..60cd9487d 100644 --- a/lib/managers/music_session_manager.rb +++ b/lib/managers/music_session_manager.rb @@ -24,7 +24,7 @@ class MusicSessionManager < BaseManager music_session.band = band music_session.legal_terms = legal_terms - genres = genres + #genres = genres @log.debug "Genres class: " + genres.class.to_s() unless genres.nil? @@ -37,7 +37,11 @@ class MusicSessionManager < BaseManager music_session.save unless music_session.errors.any? + # save session parameters for next session User.save_session_settings(user, music_session) + + # save session history + MusicSessionHistory.save(music_session) # auto-join this user into the newly created session connection = ConnectionManager.new.join_music_session(user.id, client_id, music_session.id, true, tracks) @@ -78,6 +82,9 @@ class MusicSessionManager < BaseManager end music_session.save + + # save session history (only thing that could change is description) + MusicSessionHistory.save(music_session) end end diff --git a/spec/requests/music_sessions_api_spec.rb b/spec/requests/music_sessions_api_spec.rb index 6be931190..4d1e9388d 100644 --- a/spec/requests/music_sessions_api_spec.rb +++ b/spec/requests/music_sessions_api_spec.rb @@ -52,7 +52,6 @@ describe "Music Session API ", :type => :api do get '/api/sessions.json' music_sessions = JSON.parse(last_response.body) - music_session = music_sessions[0] music_session["id"].should == music_sessions[0]["id"] music_session["musician_access"].should be_true @@ -78,6 +77,17 @@ describe "Music Session API ", :type => :api do session_settings["fan_chat"].should be_true session_settings["fan_access"].should be_true + # test session history + get '/api/users/' + user.id + '/session_history.json' + last_response.status.should == 200 + session_history = JSON.parse(last_response.body) + session_history[0]["user_id"].to_s.should == user.id + session_history[0]["band_id"].should == music_session["band_id"] + session_history[0]["description"].should == music_session["description"] + + get '/api/users/' + user.id + '/session_history/' + music_session["id"] + '/users.json' + #puts last_response.body + # test Track-specific APIs get "/api/sessions/#{music_session["id"]}/tracks.json", "CONTENT_TYPE" => 'application/json' last_response.status.should == 200