104 lines
3.7 KiB
Ruby
104 lines
3.7 KiB
Ruby
#coding=utf-8
|
||
|
||
module Mobile
|
||
module Apis
|
||
class Homeworks < Grape::API
|
||
|
||
def self.get_service
|
||
HomeworkService.new
|
||
end
|
||
|
||
resources :homeworks do
|
||
desc "作业详情"
|
||
params do
|
||
requires :id, type: Integer, desc: "作业ID"
|
||
end
|
||
route_param :id do
|
||
get do
|
||
homework = Homeworks.get_service.show_homework params
|
||
present :data, homework, with: Mobile::Entities::Homework
|
||
present :status, 0
|
||
end
|
||
end
|
||
|
||
desc "我的作品列表"
|
||
params do
|
||
requires :token, type: String
|
||
end
|
||
get ':user_id/homework_attachs' do
|
||
ue = Homeworks.get_service.my_homework_list params,current_user.nil? ? User.find(2):current_user
|
||
present :data, ue,with: Mobile::Entities::Course
|
||
present :status, 0
|
||
end
|
||
|
||
desc "启动匿评"
|
||
params do
|
||
requires :token, type: String
|
||
end
|
||
post ':id/start_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
|
||
|
||
desc "关闭匿评"
|
||
params do
|
||
requires :token, type: String
|
||
end
|
||
post ':id/stop_anonymous_comment' do
|
||
Homeworks.get_service.stop_anonymous_comment params,current_user.nil? ? User.find(2):current_user
|
||
present :status, 0
|
||
end
|
||
|
||
desc "匿评作品详情"
|
||
params do
|
||
requires :token, type: String
|
||
end
|
||
get ':homework_id/anonymous_works_show' do
|
||
works,par = Homeworks.get_service.anonymous_works_show params.merge(:id => params[:homework_id]),current_user.nil? ? User.find(2):current_user
|
||
present :data, works ,with: Mobile::Entities::HomeworkAttach
|
||
present :otherdata,par,with: Mobile::Entities::AnonymousWorksParams
|
||
present :status, 0
|
||
end
|
||
|
||
desc "作品打分"
|
||
params do
|
||
requires :token, type: String
|
||
requires :is_teacher, type: String,desc: '是否为教师(匿评作品详情返回的结果中可获取此参数的值)'
|
||
requires :is_anonymous_comments, type: String, desc: '是否为匿评(匿评作品详情返回的结果中可获取此参数的值)'
|
||
optional :stars_value, type: Integer,desc: '用户给出的评分'
|
||
optional :cur_page,type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||
optional :cur_type, type: Integer,desc: '匿评作品详情返回的结果中可获取此参数的值'
|
||
optional :user_message, type: String, desc: '用户评论'
|
||
end
|
||
|
||
post ':homework_id/scoring' do
|
||
cs_params = {
|
||
new_form: params.reject{|k,v| [:token,:is_teacher,:is_anonymous_comments,:stars_value,:cur_page,:cur_type,:homework_id].include?(k)},
|
||
token: params[:token],
|
||
is_teacher: params[:is_teacher],
|
||
is_anonymous_comments: params[:is_anonymous_comments],
|
||
stars_value: params[:stars_value],
|
||
cur_page: params[:cur_page],
|
||
cur_type: params[:cur_type],
|
||
homework_id: params[:homework_id]
|
||
}
|
||
Homeworks.get_service.add_score_and_jour cs_params,current_user
|
||
present :status, 0
|
||
end
|
||
|
||
|
||
end
|
||
end
|
||
end
|
||
end
|