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

39 lines
1.2 KiB
Ruby
Raw Normal View History

2015-01-21 11:28:09 +08:00
module Mobile
module Entities
class HomeworkAttach < Grape::Entity
2015-01-22 09:30:29 +08:00
include Redmine::I18n
2015-01-21 11:28:09 +08:00
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)
2015-01-22 09:30:29 +08:00
if field == :created_at
format_time(f.send(:created_at))
else
f.send(field)
end
2015-01-21 11:28:09 +08:00
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?)
end
end
end
end
end
homework_attach_expose :id
homework_attach_expose :name
homework_attach_expose :homework_times
2015-01-22 09:30:29 +08:00
homework_attach_expose :description
homework_attach_expose :created_at
expose :attachments,using: Mobile::Entities::Attachment do |f, opt|
if f.respond_to?(:attachments)
f.send(:attachments)
end
end
2015-01-21 11:28:09 +08:00
#homework_attach_expose :user
end
end
end