socialforge/app/api/mobile/entities/homework_attach.rb

42 lines
1.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Mobile
module Entities
class HomeworkAttach < Grape::Entity
include Redmine::I18n
def self.homework_attach_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
f[field]
elsif f.is_a?(::HomeworkAttach)
if f.respond_to?(field)
if field == :created_at
format_time(f.send(:created_at))
else
f.send(field)
end
else
case field
when :homework_times
f.bid.courses.first.homeworks.index(f.bid) + 1 unless (f.bid.nil? || f.bid.courses.nil? || f.bid.courses.first.nil?)
when :comment_status
f.bid.comment_status
end
end
end
end
end
homework_attach_expose :id
homework_attach_expose :name
homework_attach_expose :homework_times
homework_attach_expose :description
homework_attach_expose :created_at
#comment_status 0:所属作业尚未开启匿评1匿评中 2匿评结束
homework_attach_expose :comment_status
expose :attachments,using: Mobile::Entities::Attachment do |f, opt|
if f.respond_to?(:attachments)
f.send(:attachments)
end
end
end
end
end