57 lines
1.6 KiB
Ruby
57 lines
1.6 KiB
Ruby
module Mobile
|
|
module Entities
|
|
#普通留言
|
|
class Jours < Grape::Entity
|
|
include Redmine::I18n
|
|
def self.jours_expose(field)
|
|
expose field do |f,opt|
|
|
if f.is_a?(Hash) && f.key?(field)
|
|
f[field]
|
|
elsif f.is_a?(::JournalsForMessage) && f.respond_to?(field)
|
|
if field == :created_on
|
|
format_time(f.send(field))
|
|
else
|
|
f.send(field)
|
|
end
|
|
else
|
|
case field
|
|
when :lasted_comment
|
|
time_from_now f.created_on
|
|
when :reply_count
|
|
f.children.count
|
|
when :message_praise_count
|
|
get_activity_praise_num(f)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
jours_expose :id
|
|
jours_expose :jour_type
|
|
jours_expose :jour_id
|
|
expose :user,using: Mobile::Entities::User do |f, opt|
|
|
f.user
|
|
end
|
|
jours_expose :created_on
|
|
jours_expose :lasted_comment
|
|
jours_expose :notes
|
|
jours_expose :m_reply_id
|
|
jours_expose :m_parent_id
|
|
jours_expose :reply_count
|
|
jours_expose :message_praise_count
|
|
expose :course,using:Mobile::Entities::Course do |f,opt|
|
|
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
|
|
f.course
|
|
end
|
|
end
|
|
expose :reply_user,using: Mobile::Entities::User do |f, opt|
|
|
f.at_user
|
|
end
|
|
expose :child_reply,using: Mobile::Entities::Jours do |f, opt|
|
|
if f.is_a?(::JournalsForMessage)
|
|
f.children
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|