mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Merge two similar category serializers (#26653)
CategoryBadgeSerializer and TopicCategorySerializer are too similar and are used in similar contexts. This commit merges the two into a single CategoryBadgeSerializer.
This commit is contained in:
parent
9638ce17fa
commit
6281f5d768
@ -1,5 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CategoryBadgeSerializer < ApplicationSerializer
|
||||
attributes :id, :name, :color, :slug, :parent_category_id
|
||||
attributes :id, :name, :slug, :color, :text_color, :read_restricted, :parent_category_id
|
||||
|
||||
def include_parent_category_id?
|
||||
parent_category_id.present?
|
||||
end
|
||||
|
||||
def name
|
||||
if object.uncategorized?
|
||||
I18n.t("uncategorized_category_name", locale: SiteSetting.default_locale)
|
||||
else
|
||||
object.name
|
||||
end
|
||||
end
|
||||
|
||||
def description_text
|
||||
if object.uncategorized?
|
||||
I18n.t("category.uncategorized_description", locale: SiteSetting.default_locale)
|
||||
else
|
||||
object.description_text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,32 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TopicCategorySerializer < ApplicationSerializer
|
||||
attributes :id,
|
||||
:name,
|
||||
:color,
|
||||
:text_color,
|
||||
:slug,
|
||||
:description_text,
|
||||
:read_restricted,
|
||||
:parent_category_id
|
||||
|
||||
def include_parent_category_id?
|
||||
parent_category_id
|
||||
end
|
||||
|
||||
def name
|
||||
if object.uncategorized?
|
||||
I18n.t("uncategorized_category_name", locale: SiteSetting.default_locale)
|
||||
else
|
||||
object.name
|
||||
end
|
||||
end
|
||||
|
||||
def description_text
|
||||
if object.uncategorized?
|
||||
I18n.t("category.uncategorized_description", locale: SiteSetting.default_locale)
|
||||
else
|
||||
object.description_text
|
||||
end
|
||||
end
|
||||
end
|
@ -12,7 +12,7 @@ class TopicListSerializer < ApplicationSerializer
|
||||
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
|
||||
has_many :shared_drafts, serializer: TopicListItemSerializer, embed: :objects
|
||||
has_many :tags, serializer: TagSerializer, embed: :objects
|
||||
has_many :categories, serializer: TopicCategorySerializer, embed: :objects
|
||||
has_many :categories, serializer: CategoryBadgeSerializer, embed: :objects
|
||||
|
||||
def can_create_topic
|
||||
scope.can_create?(Topic)
|
||||
|
@ -83,7 +83,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
|
||||
has_one :details, serializer: TopicViewDetailsSerializer, root: false, embed: :objects
|
||||
has_many :pending_posts, serializer: TopicPendingPostSerializer, root: false, embed: :objects
|
||||
has_many :categories, serializer: TopicCategorySerializer, embed: :objects
|
||||
has_many :categories, serializer: CategoryBadgeSerializer, embed: :objects
|
||||
|
||||
has_one :published_page, embed: :objects
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user