2014-03-05 20:52:20 +08:00
|
|
|
class UserBadgeSerializer < ApplicationSerializer
|
2014-07-01 20:00:31 +08:00
|
|
|
attributes :id, :granted_at, :count, :post_id, :post_number
|
2014-03-05 20:52:20 +08:00
|
|
|
|
|
|
|
has_one :badge
|
2014-04-18 00:27:42 +08:00
|
|
|
has_one :user, serializer: BasicUserSerializer, root: :users
|
2014-03-05 20:52:20 +08:00
|
|
|
has_one :granted_by, serializer: BasicUserSerializer, root: :users
|
2014-06-28 03:08:03 +08:00
|
|
|
has_one :topic, serializer: BasicTopicSerializer
|
2014-05-21 15:22:42 +08:00
|
|
|
|
|
|
|
def include_count?
|
|
|
|
object.respond_to? :count
|
|
|
|
end
|
2014-06-28 03:08:03 +08:00
|
|
|
|
|
|
|
def include_post_id?
|
2014-07-01 20:00:31 +08:00
|
|
|
object.post_id && object.post
|
2014-06-28 03:08:03 +08:00
|
|
|
end
|
2014-07-01 20:00:31 +08:00
|
|
|
|
2014-06-28 03:08:03 +08:00
|
|
|
alias :include_topic? :include_post_id?
|
|
|
|
|
2014-07-01 20:00:31 +08:00
|
|
|
def post_number
|
|
|
|
object.post && object.post.post_number
|
|
|
|
end
|
|
|
|
|
2014-06-28 03:08:03 +08:00
|
|
|
def topic
|
|
|
|
object.post.topic
|
|
|
|
end
|
2014-03-05 20:52:20 +08:00
|
|
|
end
|