diff --git a/ruby/lib/jam_ruby/models/music_session_comment.rb b/ruby/lib/jam_ruby/models/music_session_comment.rb index 71fa8ae9a..b23383b33 100644 --- a/ruby/lib/jam_ruby/models/music_session_comment.rb +++ b/ruby/lib/jam_ruby/models/music_session_comment.rb @@ -7,8 +7,13 @@ module JamRuby default_scope order('created_at DESC') - belongs_to :music_session, :class_name => "JamRuby::MusicSessionHistory", :foreign_key => "music_session_id" - belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "creator_id" + belongs_to(:music_session_history, + :class_name => "JamRuby::MusicSessionHistory", + :foreign_key => "music_session_id") + + belongs_to(:user, + :class_name => "JamRuby::User", + :foreign_key => "creator_id") end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/music_session_history.rb b/ruby/lib/jam_ruby/models/music_session_history.rb index 045515d38..d1b41016a 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -130,5 +130,16 @@ module JamRuby .order('created_at DESC') end + def comments + @comments ||= JamRuby::MusicSessionComment + .where(:music_session_id => self.music_session_id) + .order('created_at DESC') + end + + def likes + @likes ||= JamRuby::MusicSessionLiker + .where(:music_session_id => self.music_session_id) + end + end end diff --git a/ruby/lib/jam_ruby/models/music_session_liker.rb b/ruby/lib/jam_ruby/models/music_session_liker.rb index a7d89fc72..538822c6e 100644 --- a/ruby/lib/jam_ruby/models/music_session_liker.rb +++ b/ruby/lib/jam_ruby/models/music_session_liker.rb @@ -5,8 +5,13 @@ module JamRuby self.primary_key = 'id' - belongs_to :music_session, :class_name => "JamRuby::MusicSessionHistory", :foreign_key => "music_session_id" - belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "liker_id" + belongs_to(:music_session_history, + :class_name => "JamRuby::MusicSessionHistory", + :foreign_key => "music_session_id") + + belongs_to(:user, + :class_name => "JamRuby::User", + :foreign_key => "liker_id") end end \ No newline at end of file diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 556512a40..c8206317c 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -35,7 +35,6 @@ } function updateSession(id, newSession, onSuccess) { - logger.debug('Rest.updateSession'); return $.ajax('/api/sessions/' + id, { type: "PUT", data : newSession, @@ -44,6 +43,56 @@ }); } + function addSessionComment(sessionId, userId, comment) { + return $.ajax({ + url: '/api/sessions/' + sessionId + "/comments", + type: "POST", + data : JSON.stringify({"comment": comment, "user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addSessionLike(sessionId, userId) { + return $.ajax({ + url: '/api/sessions/' + sessionId + "/likes", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingComment(recordingId, userId, comment) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/comments", + type: "POST", + data : JSON.stringify({"comment": comment, "user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingLike(recordingId, userId) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/likes", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + + function addRecordingPlay(recordingId, userId) { + return $.ajax({ + url: '/api/recordings/' + recordingId + "/plays", + type: "POST", + data : JSON.stringify({"user_id": userId}), + dataType : 'json', + contentType: 'application/json' + }); + } + function getBand(bandId) { return $.ajax({ type: "GET", @@ -705,6 +754,11 @@ this.getBandFollowing = getBandFollowing; this.getBands = getBands; this.updateSession = updateSession; + this.addSessionComment = addSessionComment; + this.addSessionLike = addSessionLike; + this.addRecordingComment = addRecordingComment; + this.addRecordingLike = addRecordingLike; + this.addRecordingPlay = addRecordingPlay; this.getSession = getSession; this.getClientDownloads = getClientDownloads; this.createInvitation = createInvitation; diff --git a/web/app/controllers/api_music_sessions_controller.rb b/web/app/controllers/api_music_sessions_controller.rb index ecfd62359..cf0aad771 100644 --- a/web/app/controllers/api_music_sessions_controller.rb +++ b/web/app/controllers/api_music_sessions_controller.rb @@ -89,7 +89,6 @@ class ApiMusicSessionsController < ApiController end def participant_create - @connection = MusicSessionManager.new.participant_create( current_user, params[:id], @@ -243,14 +242,17 @@ class ApiMusicSessionsController < ApiController def add_comment if params[:id].blank? render :json => { :message => "Session ID is required" }, :status => 400 + return end if params[:user_id].blank? render :json => { :message => "User ID is required" }, :status => 400 + return end if params[:comment].blank? render :json => { :message => "Comment is required" }, :status => 400 + return end comment = MusicSessionComment.new @@ -262,18 +264,17 @@ class ApiMusicSessionsController < ApiController if comment.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_like if params[:id].blank? render :json => { :message => "Session ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end liker = MusicSessionLiker.new @@ -284,8 +285,10 @@ class ApiMusicSessionsController < ApiController if liker.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index ce06547c6..1947b7baa 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -83,14 +83,17 @@ class ApiRecordingsController < ApiController def add_comment if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 + return end if params[:user_id].blank? render :json => { :message => "User ID is required" }, :status => 400 + return end if params[:comment].blank? render :json => { :message => "Comment is required" }, :status => 400 + return end comment = RecordingComment.new @@ -102,18 +105,17 @@ class ApiRecordingsController < ApiController if comment.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_like if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end liker = RecordingLiker.new @@ -124,18 +126,17 @@ class ApiRecordingsController < ApiController if liker.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end def add_play if params[:id].blank? render :json => { :message => "Recording ID is required" }, :status => 400 - end - - if params[:user_id].blank? - render :json => { :message => "User ID is required" }, :status => 400 + return end play = RecordingPlay.new @@ -146,8 +147,10 @@ class ApiRecordingsController < ApiController if play.errors.any? render :json => { :message => "Unexpected error occurred" }, :status => 500 + return else render :json => {}, :status => 201 + return end end diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index 1ba28d42f..2bad9aa50 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -27,14 +27,16 @@