Sha256: 90e4ed193fcacfd26205bd414a4a01114a7b1ded60caf66ca2dc1ec6fc31452c

Contents?: true

Size: 1.29 KB

Versions: 23

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    class CommentVoteSerializer < Decidim::Exporters::Serializer
      include Decidim::ResourceHelper

      # Serializes a comment
      def serialize
        {
          id: resource.id,
          weight: resource.weight,
          comment: {
            id: resource.comment.id,
            created_at: resource.comment.created_at,
            body: resource.comment.body,
            author: {
              id: resource.comment.author.id,
              name: resource.comment.author.name
            },
            alignment: resource.comment.alignment,
            depth: resource.comment.depth,
            user_group: {
              id: resource.comment.user_group.try(:id),
              name: resource.comment.user_group.try(:name)
            },
            commentable_id: resource.comment.decidim_commentable_id,
            commentable_type: resource.comment.decidim_commentable_type,
            root_commentable_url: root_commentable_url

          },
          created_at: resource.created_at,
          updated_at: resource.updated_at
        }
      end

      private

      def root_commentable_url
        @root_commentable_url ||= Decidim::ResourceLocatorPresenter.new(resource.comment.root_commentable).url
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
decidim-comments-0.22.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.21.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.20.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.20.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.19.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.18.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.19.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.17.2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.18.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.17.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.16.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.17.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.16.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.15.2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.15.1 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.15.0 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.14.4 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.14.3 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.14.2 lib/decidim/comments/comment_vote_serializer.rb
decidim-comments-0.14.1 lib/decidim/comments/comment_vote_serializer.rb