Class: PostInteractionPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/post_interaction_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(post, current_user) ⇒ PostInteractionPresenter

Returns a new instance of PostInteractionPresenter.


4
5
6
7
# File 'app/presenters/post_interaction_presenter.rb', line 4

def initialize(post, current_user)
  @post = post
  @current_user = current_user
end

Instance Method Details

#as_countersObject


21
22
23
24
25
26
27
# File 'app/presenters/post_interaction_presenter.rb', line 21

def as_counters
  {
    comments: @post.comments_count,
    likes:    @post.likes_count,
    reshares: @post.reshares_count
  }
end

#as_json(_options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
# File 'app/presenters/post_interaction_presenter.rb', line 9

def as_json(_options={})
  {
    likes:          as_api(@post.likes),
    reshares:       PostPresenter.as_collection(@post.reshares, :as_json, @current_user),
    comments:       CommentPresenter.as_collection(@post.comments.order("created_at ASC")),
    participations: as_api(participations),
    comments_count: @post.comments_count,
    likes_count:    @post.likes_count,
    reshares_count: @post.reshares_count
  }
end