2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-03-05 06:52:20 -06:00
|
|
|
class UserBadgeSerializer < ApplicationSerializer
|
2022-10-26 22:26:14 -05:00
|
|
|
include UserBadgePostAndTopicAttributesMixin
|
2016-01-18 00:59:07 -06:00
|
|
|
|
|
|
|
class UserSerializer < BasicUserSerializer
|
2018-12-06 05:18:52 -06:00
|
|
|
include UserPrimaryGroupMixin
|
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
attributes :name, :moderator, :admin
|
2016-01-18 00:59:07 -06:00
|
|
|
end
|
|
|
|
|
2020-04-20 12:03:25 -05:00
|
|
|
attributes :id, :granted_at, :created_at, :count, :post_id, :post_number
|
2014-03-05 06:52:20 -06:00
|
|
|
|
|
|
|
has_one :badge
|
2016-01-18 00:59:07 -06:00
|
|
|
has_one :user, serializer: UserSerializer, root: :users
|
|
|
|
has_one :granted_by, serializer: UserSerializer, root: :users
|
2014-06-27 14:08:03 -05:00
|
|
|
has_one :topic, serializer: BasicTopicSerializer
|
2014-05-21 02:22:42 -05:00
|
|
|
|
|
|
|
def include_count?
|
|
|
|
object.respond_to? :count
|
|
|
|
end
|
2014-06-27 14:08:03 -05:00
|
|
|
|
|
|
|
def include_post_id?
|
2022-10-26 22:26:14 -05:00
|
|
|
include_post_attributes?
|
2014-06-27 14:08:03 -05:00
|
|
|
end
|
2014-07-01 07:00:31 -05:00
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
alias include_post_number? include_post_id?
|
2014-06-27 14:08:03 -05:00
|
|
|
|
2014-07-01 07:00:31 -05:00
|
|
|
def post_number
|
|
|
|
object.post && object.post.post_number
|
|
|
|
end
|
|
|
|
|
2014-06-27 14:08:03 -05:00
|
|
|
def topic
|
|
|
|
object.post.topic
|
|
|
|
end
|
2022-10-26 22:26:14 -05:00
|
|
|
|
|
|
|
def include_topic?
|
|
|
|
include_topic_attributes?
|
|
|
|
end
|
2014-03-05 06:52:20 -06:00
|
|
|
end
|