socialforge/app/api/mobile/apis/homeworks.rb

119 lines
4.3 KiB
Ruby
Raw Normal View History

2015-01-04 14:55:45 +08:00
#coding=utf-8
module Mobile
module Apis
class Homeworks < Grape::API
2015-01-12 17:19:18 +08:00
def self.get_service
2015-01-13 16:00:17 +08:00
HomeworkService.new
2015-01-04 14:55:45 +08:00
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
2015-01-04 14:55:45 +08:00
end
end
2015-01-12 17:19:18 +08:00
2015-01-21 11:28:09 +08:00
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
2015-01-21 15:29:05 +08:00
desc "启动匿评"
params do
requires :token, type: String
end
2015-01-21 15:37:59 +08:00
post ':id/start_anonymous_comment' do
2015-01-21 15:29:05 +08:00
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
2015-01-21 15:37:59 +08:00
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
2015-01-22 09:30:29 +08:00
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
2015-01-22 09:30:29 +08:00
present :data, works ,with: Mobile::Entities::HomeworkAttach
present :otherdata,par,with: Mobile::Entities::AnonymousWorksParams
2015-01-22 09:30:29 +08:00
present :status, 0
end
2015-02-03 15:10:21 +08:00
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
desc '创建作业'
params do
requires :token,type:String
requires :work_name,type:String,desc:'作业名称'
requires :work_desc,type:String,desc:'作业描述'
requires :work_deadline,type:String,desc:'截止日期'
requires :is_blind_appr,type:Integer,desc:'是否匿评'
requires :blind_appr_num,type:Integer,desc:'匿评分配数'
requires :course_id,type:Integer,desc: '课程id'
end
post 'create_home_work' do
Homeworks.get_service.create_home_work params,current_user
present :status, 0
end
2015-01-22 09:30:29 +08:00
2015-01-21 11:28:09 +08:00
end
2015-01-04 14:55:45 +08:00
end
end
end