#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 = Homeworks.get_service.anonymous_works_show params present :data, works ,with: Mobile::Entities::HomeworkAttach present :status, 0 end end end end end