53 lines
1.6 KiB
Ruby
53 lines
1.6 KiB
Ruby
|
# encoding: utf-8
|
||
|
module Mobile
|
||
|
module Entities
|
||
|
class Whomework <Grape::Entity
|
||
|
include ApiHelper
|
||
|
include ApplicationHelper
|
||
|
include Redmine::I18n
|
||
|
def self.whomework_expose(f)
|
||
|
expose f do |wh, opt|
|
||
|
if wh.is_a?(Hash) && wh.key?(f)
|
||
|
if f == :created_at
|
||
|
format_time(wh[f])
|
||
|
else
|
||
|
wh[f]
|
||
|
end
|
||
|
elsif wh.is_a?(::HomeworkCommon)
|
||
|
if wh.respond_to?(f)
|
||
|
wh.send(f)
|
||
|
else
|
||
|
case f
|
||
|
when :absence_penalty
|
||
|
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
||
|
when :evaluation_start
|
||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
||
|
when :evaluation_end
|
||
|
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
expose :name
|
||
|
expose :description
|
||
|
expose :publish_time
|
||
|
expose :end_time
|
||
|
expose :homework_type
|
||
|
expose :late_penalty
|
||
|
expose :course_id
|
||
|
expose :anonymous_comment
|
||
|
expose :quotes
|
||
|
expose :is_open
|
||
|
whomework_expose :created_at
|
||
|
whomework_expose :absence_penalty
|
||
|
whomework_expose :evaluation_start
|
||
|
whomework_expose :evaluation_end
|
||
|
expose :author, using: Mobile::Entities::User do |w, opt|
|
||
|
if w.is_a?(::HomeworkCommon)
|
||
|
w.user
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|