2015-04-01 00:58:56 +08:00
|
|
|
require_dependency 'application_serializer'
|
|
|
|
|
|
|
|
class NewPostResultSerializer < ApplicationSerializer
|
|
|
|
attributes :action,
|
|
|
|
:post,
|
|
|
|
:errors,
|
2015-04-25 03:44:59 +08:00
|
|
|
:success,
|
2015-04-29 03:06:27 +08:00
|
|
|
:pending_count,
|
|
|
|
:reason
|
2015-04-01 00:58:56 +08:00
|
|
|
|
|
|
|
def post
|
|
|
|
post_serializer = PostSerializer.new(object.post, scope: scope, root: false)
|
|
|
|
post_serializer.draft_sequence = DraftSequence.current(scope.user, object.post.topic.draft_key)
|
|
|
|
post_serializer.as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_post?
|
|
|
|
object.post.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def success
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_success?
|
|
|
|
@object.success?
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
object.errors.full_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_errors?
|
|
|
|
!object.errors.empty?
|
|
|
|
end
|
|
|
|
|
2015-04-29 03:06:27 +08:00
|
|
|
def reason
|
|
|
|
object.reason
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_reason?
|
|
|
|
reason.present?
|
|
|
|
end
|
|
|
|
|
2015-04-01 00:58:56 +08:00
|
|
|
def action
|
|
|
|
object.action
|
|
|
|
end
|
|
|
|
|
2015-04-25 03:44:59 +08:00
|
|
|
def pending_count
|
|
|
|
object.pending_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_pending_count?
|
|
|
|
pending_count.present?
|
|
|
|
end
|
|
|
|
|
2015-04-01 00:58:56 +08:00
|
|
|
end
|