This commit is contained in:
2026-05-01 04:43:30 +09:00
parent a7020fb129
commit fa8eb66535
9 changed files with 128 additions and 24 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ class PostsController < ApplicationController
render json: PostRepr.base(post, current_user)
.merge(tags: build_tag_tree_for(post.tags),
related: post.related(limit: 20))
related: PostRepr.many(post.related(limit: 20)))
end
def create
+13 -5
View File
@@ -37,18 +37,26 @@ class Post < ApplicationRecord
def parent_posts = parents
def child_posts = children
def sibling_posts
parent_post_ids = parent_posts.order(:id).pluck(:id)
parent_post_ids.to_h { [_1, PostImplication.where(parent_post: _1).map(&:post)] }
end
def as_json options = { }
super(options).merge({ thumbnail: thumbnail.attached? ?
Rails.application.routes.url_helpers.rails_blob_url(
thumbnail, only_path: false) :
nil })
super(options).merge(thumbnail: thumbnail.attached? ?
Rails.application.routes.url_helpers.rails_blob_url(
thumbnail, only_path: false) :
nil)
rescue
super(options).merge(thumbnail: nil)
end
def snapshot_tag_names = tags.joins(:tag_name).order('tag_names.name').pluck('tag_names.name')
def snapshot_parent_post_ids = parents.order(:parent_post_id).pulck(:parent_post_id)
def snapshot_parent_post_ids = parents.order(:parent_post_id).pluck(:parent_post_id)
def related limit: nil
ids = post_similarities.order(cos: :desc)
+1 -1
View File
@@ -3,7 +3,7 @@
module PostRepr
BASE = { include: { tags: TagRepr::BASE, uploaded_user: UserRepr::BASE },
methods: [:parent_posts] }.freeze
methods: [:parent_posts, :child_posts, :sibling_posts] }.freeze
module_function