Make PostPresenter inherit from BasePresenter

closes #6315
This commit is contained in:
theworldbright 2015-08-21 10:24:42 -07:00 committed by Jonne Haß
parent 335b1c32aa
commit 6e74ee7d21
3 changed files with 4 additions and 7 deletions

View file

@ -9,6 +9,7 @@
* Refactor HomeController#toggle\_mobile [#6260](https://github.com/diaspora/diaspora/pull/6260)
* Extract CommentService from CommentsController [#6307](https://github.com/diaspora/diaspora/pull/6307)
* Extract user/profile discovery into the diaspora\_federation-rails gem [#6310](https://github.com/diaspora/diaspora/pull/6310)
* Refactor PostPresenter [#6315](https://github.com/diaspora/diaspora/pull/6315)
## Bug fixes
* Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212)

View file

@ -7,7 +7,7 @@ class PostInteractionPresenter
def as_json(_options={})
{
likes: as_api(@post.likes),
reshares: PostPresenter.collection_json(@post.reshares, @current_user),
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,

View file

@ -1,17 +1,13 @@
class PostPresenter
class PostPresenter < BasePresenter
include PostsHelper
attr_accessor :post, :current_user
attr_accessor :post
def initialize(post, current_user=nil)
@post = post
@current_user = current_user
end
def self.collection_json(collection, current_user)
collection.map {|post| PostPresenter.new(post, current_user) }
end
def as_json(_options={})
@post.include_root_in_json = false
@post.as_json(only: directly_retrieved_attributes).merge(non_directly_retrieved_attributes)