46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
module Mobile
|
|
module Entities
|
|
class Message < Grape::Entity
|
|
include ApplicationHelper
|
|
include ApiHelper
|
|
def self.message_expose(f)
|
|
expose f do |u,opt|
|
|
if u.is_a?(Hash) && u.key?(f)
|
|
u[f]
|
|
elsif u.is_a?(::Message)
|
|
if u.respond_to?(f)
|
|
if f == :created_on
|
|
format_time( u.send(f))
|
|
else
|
|
u.send(f)
|
|
end
|
|
else
|
|
# case f
|
|
# when :xx
|
|
# #
|
|
# end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
expose :user, using: Mobile::Entities::User do |c, opt|
|
|
if c.is_a?(::Message)
|
|
c.author
|
|
end
|
|
end
|
|
message_expose :board_id
|
|
message_expose :subject
|
|
message_expose :content
|
|
message_expose :replies_count
|
|
message_expose :created_on
|
|
message_expose :id
|
|
expose :message_children,using:Mobile::Entities::Message do |c,opt|
|
|
if c.is_a? (::Message)
|
|
c.children
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |