From cd274cad0df6ac11bdd9470ab03a595eb5b51558 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Tue, 21 Feb 2012 22:13:46 -0800 Subject: [PATCH] adding likes, reshares and comments in a naive presenter way --- app/presenters/post_presenter.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index f076fd4d3..41440bd27 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -19,12 +19,27 @@ class PostPresenter :reshares_count => self.post.reshares.count, :user_reshare => self.user_reshare, :next_post => self.next_post_path, - :previous_post => self.previous_post_path + :previous_post => self.previous_post_path, + :likes => self.likes, + :reshares => self.reshares, + :comments => self.comments }), :templateName => template_name } end + def comments + as_api(post.comments) + end + + def likes + as_api(post.likes) + end + + def reshares + as_api(post.reshares) + end + def user_like return unless user_signed_in? if like = post.likes.where(:author_id => person.id).first @@ -70,6 +85,12 @@ class PostPresenter protected + def as_api(collection) + collection.includes(:author => :profile).all.map do |element| + element.as_api_response(:backbone) + end + end + def post_base if current_user current_user.posts_from(self.post.author)