50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
module Mobile
|
|
module Entities
|
|
class BlogComment < Grape::Entity
|
|
include ApplicationHelper
|
|
include ApiHelper
|
|
def self.blog_comment_expose(f)
|
|
expose f do |u,opt|
|
|
if u.is_a?(Hash) && u.key?(f)
|
|
u[f]
|
|
elsif u.is_a?(::BlogComment)
|
|
if u.respond_to?(f)
|
|
if f == :created_at
|
|
format_time( u.send(f))
|
|
else
|
|
u.send(f)
|
|
end
|
|
else
|
|
case f
|
|
when :blog_praise_count
|
|
get_activity_praise_num(u)
|
|
when :lasted_comment
|
|
time_from_now(u.created_at)
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
expose :user, using: Mobile::Entities::User do |c, opt|
|
|
if c.is_a?(::BlogComment)
|
|
c.author
|
|
end
|
|
end
|
|
blog_comment_expose :blog_id
|
|
blog_comment_expose :title
|
|
blog_comment_expose :content
|
|
blog_comment_expose :comments_count
|
|
blog_comment_expose :created_at
|
|
blog_comment_expose :lasted_comment
|
|
blog_comment_expose :id
|
|
blog_comment_expose :blog_praise_count
|
|
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
|
if c.is_a? (::BlogComment)
|
|
c.children
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |