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
|
2015-01-20 15:17:02 +08:00
|
|
|
|
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
|
2015-01-22 17:21:15 +08:00
|
|
|
|
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
|
2015-01-22 17:21:15 +08:00
|
|
|
|
present :otherdata,par,with: Mobile::Entities::AnonymousWorksParams
|
2015-01-22 09:30:29 +08:00
|
|
|
|
present :status, 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2015-01-21 11:28:09 +08:00
|
|
|
|
end
|
2015-01-04 14:55:45 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|