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

57 lines
1.5 KiB
Ruby
Raw Normal View History

2015-06-26 09:19:23 +08:00
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
2016-03-30 17:49:05 +08:00
case f
when :course_project_name
if u.board.project_id == -1
u.course.name
else
u.project.name
end
when :lasted_comment
time_from_now u.created_on
2016-04-01 20:46:38 +08:00
when :message_praise_count
get_activity_praise_num(u)
2016-03-30 17:49:05 +08:00
end
2015-06-26 09:19:23 +08:00
end
end
end
end
expose :user, using: Mobile::Entities::User do |c, opt|
if c.is_a?(::Message)
c.author
end
end
2016-03-30 17:49:05 +08:00
message_expose :course_project_name
2015-06-26 09:19:23 +08:00
message_expose :board_id
message_expose :subject
message_expose :content
message_expose :replies_count
2016-04-01 20:46:38 +08:00
message_expose :message_praise_count
2015-06-26 09:19:23 +08:00
message_expose :created_on
message_expose :id
2016-03-30 17:49:05 +08:00
message_expose :lasted_comment
2015-06-26 09:19:23 +08:00
expose :message_children,using:Mobile::Entities::Message do |c,opt|
if c.is_a? (::Message)
c.children
end
end
end
end
end