This commit is contained in:
2026-04-14 23:54:34 +09:00
parent e72ec608f4
commit badb280dc3
6 changed files with 55 additions and 4 deletions
@@ -0,0 +1,29 @@
class PostVersionsController < ApplicationController
def index
post_id = params[:post].presence
tag_id = params[:tag].presence
page = (params[:page].presence || 1).to_i
limit = (params[:limit].presence || 20).to_i
page = 1 if page < 1
limit = 1 if limit < 1
offset = (page - 1) * limit
tag_name = nil
if tag_id
tag_name = TagName.joins(:tag).find_by(tag: { id: tag_id })
return render json: [] unless tag_name
end
q = PostVersion
q = q.where(post_id:) if post_id
q = q.where("CONCAT(' ', tags, ' ') LIKE ?", "% #{ tag_name } %") if tag_name
versions = q.order(created_at: :desc, id: :desc)
.limit(limit)
.offset(offset)
render json: { versions:, count: q.count }
end
end
+1 -1
View File
@@ -204,7 +204,7 @@ class PostsController < ApplicationController
pts = pts.where(post_id: id) if id.present?
pts = pts.where(tag_id:) if tag_id.present?
pts = pts.includes(:post, :created_user, :deleted_user,
tag: { tag_name: :wiki_page })
tag: [:materials, { tag_name: :wiki_page }])
events = []
pts.each do |pt|