ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

30 lines
785 B

  1. class PostVersionsController < ApplicationController
  2. def index
  3. post_id = params[:post].presence
  4. tag_id = params[:tag].presence
  5. page = (params[:page].presence || 1).to_i
  6. limit = (params[:limit].presence || 20).to_i
  7. page = 1 if page < 1
  8. limit = 1 if limit < 1
  9. offset = (page - 1) * limit
  10. tag_name = nil
  11. if tag_id
  12. tag_name = TagName.joins(:tag).find_by(tag: { id: tag_id })
  13. return render json: [] unless tag_name
  14. end
  15. q = PostVersion
  16. q = q.where(post_id:) if post_id
  17. q = q.where("CONCAT(' ', tags, ' ') LIKE ?", "% #{ tag_name } %") if tag_name
  18. versions = q.order(created_at: :desc, id: :desc)
  19. .limit(limit)
  20. .offset(offset)
  21. render json: { versions:, count: q.count }
  22. end
  23. end