启动匿评接口

This commit is contained in:
z9hang 2015-01-21 15:29:05 +08:00
parent b13f2b2dc8
commit 89e0f98034
3 changed files with 60 additions and 1 deletions

View File

@ -31,6 +31,25 @@ module Mobile
present :status, 0
end
desc "启动匿评"
params do
requires :token, type: String
end
post ':id/alert_homework_anonymous_comment' do
statue = Homeworks.get_service.start_anonymous_comment params,current_user.nil? ? User.find(2):current_user
messages = ""
case statue
when 1
messages = "启动成功"
when 2
messages = "启动失败作业总数大于等于2份时才能启动匿评"
when 3
messages = "已开启匿评,请务重复开启"
end
present :data,messages
present :status, statue
end
end
end
end

View File

@ -19,4 +19,10 @@ module ApiHelper
location << (user.user_extensions.location_city || '')
location
end
def get_assigned_homeworks(homeworks, n, index)
homeworks += homeworks
homeworks[index + 1 .. index + n]
end
end

View File

@ -4,6 +4,7 @@ class HomeworkService
include AttachmentsHelper
include ApplicationHelper
include WordsHelper
include ApiHelper
# 作业详情(老师才显示启动匿评,学生不显示
# many_times 第几次(作业)
@ -27,7 +28,7 @@ class HomeworkService
:description => description, :homework_state => state,:open_anonymous_evaluation => open_anonymous_evaluation}
end
# 启动作业匿评
# 启动作业匿评前提示信息
def alert_homework_anonymous_comment params
@bid = Bid.find params[:id]
@course = @bid.courses.first
@ -53,6 +54,39 @@ class HomeworkService
[@bid,@totle_size,@cur_size,@percent]
end
#启动匿评
#statue 1:启动成功2启动失败作业总数大于等于2份时才能启动匿评3:已开启匿评,请务重复开启
def start_anonymous_comment params,current_user
@bid = Bid.find(params[:id])
@course = @bid.courses.first
unless is_course_teacher(current_user,@course) || current_user.admin?
@statue = 4
raise '403'
end
if(@bid.comment_status == 0)
homeworks = @bid.homeworks
if(homeworks && homeworks.size >= 2)
homeworks.each_with_index do |homework, index|
user = homework.user
n = @bid.evaluation_num
n = n < homeworks.size ? n : homeworks.size - 1
assigned_homeworks = get_assigned_homeworks(homeworks, n, index)
assigned_homeworks.each do |h|
@homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: h.id)
@homework_evaluation.save
end
end
@bid.update_column('comment_status', 1)
@statue = 1
else
@statue = 2
end
else
@statue = 3
end
@statue
end
# 匿评作品详情
# attachs 该作品的所有附件
# filename 文件名