backend_details attempt #2

This commit is contained in:
Seth Call 2018-07-29 12:39:40 -05:00
parent bc4e5607ee
commit 753cc8e4d9
2 changed files with 16 additions and 9 deletions

View File

@ -53,7 +53,7 @@ module ValidationMessages
SELECT_AT_LEAST_ONE = "Please select at least one track" # DO NOT CHANGE THIS TEXT MESSAGE UNLESS YOU CHANGE createSession.js.erb, which is looking for it
FAN_CAN_NOT_JOIN_AS_MUSICIAN = "A fan can not join a music session as a musician"
MUSIC_SESSION_MUST_BE_SPECIFIED = "A music session must be specified"
INVITE_REQUIRED = "You must be invited to join this session"
INVITE_REQUIRED = "You must be invited to join this session"
FANS_CAN_NOT_JOIN = "Fans can not join this session"
CANT_JOIN_RECORDING_SESSION = "is currently recording"
CANT_JOIN_MULTIPLE_SESSIONS = 'You cannot join more than one music session'

View File

@ -349,18 +349,22 @@ class ApiMusicSessionsController < ApiController
def participant_rating
if @history = MusicSessionUserHistory.latest_history(params[:client_id])
if request.post?
@history.add_rating(params[:rating], params[:comment], params[:backend_details])
rating = params[:rating].to_i
comment = params[:comment]
backend_details = params[:backend_details]
@history.add_rating(rating, comment, backend_details)
@history.save
if @history.errors.any?
response.status = :unprocessable_entity
respond_with @history
return
else
if @history.good_rating? && @history.user.first_good_music_session_at.nil?
@history.user.first_good_music_session_at = Time.now
@history.user.save
end
render :json => {}, :status => :ok
end
@ -378,27 +382,30 @@ class ApiMusicSessionsController < ApiController
subject = "#{current_user.name} Rated Their #{session_type}!"
body = "Session Type: #{session_type}\n"
body << "Session Rating: #{@history.good_rating? ? "Good" : "Bad"}\n"
body << "Session Rating: #{ rating > 0 ? "Good" : "Bad"}\n"
body << "User: #{current_user.email}\n"
body << "Music Session URL: #{session_link}\n"
if lesson_link
body << "Lesson URL: #{lesson_link}\n"
end
body << "Session Comments: #{@history.rating_comment}\n"
body << "Session Comments: #{comment}\n"
if @history.backend_details
if backend_details
begin
details = JSON.parse(@history.backend_details)
body << "Backend Detail:\n" + JSON.pretty_generate(details) + "\n"
body << "Backend Detail:\n" + JSON.pretty_generate(backend_details) + "\n"
rescue Exception => e
logger.error("Unable to send out retails email due to bad backend data #{e}")
puts "Unable to send out retails ratings due to bad backend data #{e}"
logger.error("Unable to send out retails ratings due to bad backend data #{e}")
end
end
AdminMailer.jamclass_alerts({subject: subject, body: body}).deliver_now
rescue Exception => e
puts "Exception sending out ratings email. Boo #{e}"
logger.error("Exception sending out ratings email. Boo #{e}")
end
render :json => {}, :status => :ok
elsif request.get?
render :json => { :should_rate_session => @history.should_rate_session? }, :status => :ok