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

39 lines
1.2 KiB
Ruby

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?)
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
expose :attachments,using: Mobile::Entities::Attachment do |f, opt|
if f.respond_to?(:attachments)
f.send(:attachments)
end
end
#homework_attach_expose :user
end
end
end