1
0
Fork 0

Track vote methods

This commit is contained in:
Gregory Eremin 2011-10-13 17:47:19 +04:00
parent fa896c696d
commit 29147d56d7
2 changed files with 46 additions and 0 deletions

View File

@ -15,4 +15,50 @@ class TrackController < ApplicationController
end
render :json => { :result => :failed }
end
def report_unavailable
track = Track.find(params[:id])
unless track.nil? or track.available
track.available = true
track.save
render :json => { :status => :success }
return
end
render :json => { :status => :failed }
end
def report_good
track = Track.find(params[:id])
unless track.nil?
# Track is now definitely available
track.available = true
track.save
# Saving track file
vote(params[:track_id], params[:owner_id], params[:audio_id], 1)
render :json => { :status => :success }
return
end
render :json => { :status => :failed }
end
def report_bad
track = Track.find(params[:id])
unless track.nil?
# Saving track file
vote(params[:track_id], params[:owner_id], params[:audio_id], -1)
render :json => { :status => :success }
return
end
render :json => { :status => :failed }
end
private
def vote track_id, owner_id, audio_id, delta = 0
track_file = TrackFile.find_or_create_by_track_id_and_owner_id_and_audio_id(
track_id, owner_id, audio_id
){ |tf| tf.rating = 0 }
track_file.rating += delta
track_file.save
end
end