From a8377f7dcb3f7901a4d6d8548489a4e302e0d6cf Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Fri, 26 Jun 2015 09:19:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/message.rb | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 app/api/mobile/entities/message.rb diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb new file mode 100644 index 000000000..6a2ca1fb0 --- /dev/null +++ b/app/api/mobile/entities/message.rb @@ -0,0 +1,46 @@ +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 \ No newline at end of file