Representations 追加(#241) (#267)
#241 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #267
This commit was merged in pull request #267.
This commit is contained in:
@@ -36,8 +36,7 @@ class PostsController < ApplicationController
|
||||
end
|
||||
|
||||
render json: { posts: posts.map { |post|
|
||||
post.as_json(include: { tags: { only: [:id, :category, :post_count],
|
||||
methods: [:name, :has_wiki] } }).tap do |json|
|
||||
PostRepr.base(post).tap do |json|
|
||||
json['thumbnail'] =
|
||||
if post.thumbnail.attached?
|
||||
rails_storage_proxy_url(post.thumbnail, only_path: false)
|
||||
@@ -60,10 +59,7 @@ class PostsController < ApplicationController
|
||||
|
||||
viewed = current_user&.viewed?(post) || false
|
||||
|
||||
render json: (post
|
||||
.as_json(include: { tags: { only: [:id, :category, :post_count],
|
||||
methods: [:name, :has_wiki] } })
|
||||
.merge(viewed:))
|
||||
render json: PostRepr.base(post).merge(viewed:)
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -102,9 +98,7 @@ class PostsController < ApplicationController
|
||||
sync_post_tags!(post, tags)
|
||||
|
||||
post.reload
|
||||
render json: post.as_json(include: { tags: { only: [:id, :category, :post_count],
|
||||
methods: [:name, :has_wiki] } }),
|
||||
status: :created
|
||||
render json: PostRepr.base(post), status: :created
|
||||
else
|
||||
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
@@ -170,7 +164,7 @@ class PostsController < ApplicationController
|
||||
|
||||
events = []
|
||||
pts.each do |pt|
|
||||
tag = pt.tag.as_json(only: [:id, :category], methods: [:name, :has_wiki])
|
||||
tag = TagRepr.base(pt.tag)
|
||||
post = pt.post
|
||||
|
||||
events << Event.new(
|
||||
@@ -269,8 +263,7 @@ class PostsController < ApplicationController
|
||||
return nil unless tag
|
||||
|
||||
if path.include?(tag_id)
|
||||
return tag.as_json(only: [:id, :category, :post_count],
|
||||
methods: [:name, :has_wiki]).merge(children: [])
|
||||
return TagRepr.base(tag).merge(children: [])
|
||||
end
|
||||
|
||||
if memo.key?(tag_id)
|
||||
@@ -282,8 +275,7 @@ class PostsController < ApplicationController
|
||||
|
||||
children = child_ids.filter_map { |cid| build_node.(cid, new_path) }
|
||||
|
||||
memo[tag_id] = tag.as_json(only: [:id, :category, :post_count],
|
||||
methods: [:name, :has_wiki]).merge(children:)
|
||||
memo[tag_id] = TagRepr.base(tag).merge(children:)
|
||||
end
|
||||
|
||||
root_ids.filter_map { |id| build_node.call(id, []) }
|
||||
|
||||
Reference in New Issue
Block a user