docbrown/app/serializers/search/comment_serializer.rb
Jan Klimo a6ea2c9618
Migrate serialization to jsonapi-serializer (#9682)
This replaces the abandoned fast_jsonapi.
2020-08-08 15:41:44 +02:00

27 lines
694 B
Ruby

module Search
class CommentSerializer < ApplicationSerializer
attribute :id, &:search_id
attributes :path, :public_reactions_count
attribute :body_text, &:body_markdown
attribute :class_name do |comment|
comment.class.name
end
attribute :hotness_score, &:score
attribute :published do |_comment|
true
end
attribute :published_at, &:created_at
attribute :readable_publish_date_string, &:readable_publish_date
attribute :title do |comment|
comment.commentable&.title
end
attribute :user do |comment|
NestedUserSerializer.new(comment.user).serializable_hash.dig(
:data, :attributes
)
end
end
end