#59 関聯投稿一覧の追加

This commit is contained in:
2025-08-01 01:06:09 +09:00
parent 0f902f0d27
commit efb6b16412
4 changed files with 31 additions and 5 deletions
+4 -4
View File
@@ -5,16 +5,16 @@ require 'nokogiri'
class PostsController < ApplicationController
# GET /posts
def index
limit = (params[:limit] || 20).to_i
limit = params[:limit].presence&.to_i
cursor = params[:cursor].presence
q = filtered_posts.order(created_at: :desc)
q = q.where('posts.created_at < ?', Time.iso8601(cursor)) if cursor
posts = q.limit(limit + 1)
posts = limit ? q.limit(limit + 1) : q
next_cursor = nil
if posts.size > limit
if limit && posts.size > limit
next_cursor = posts.last.created_at.iso8601(6)
posts = posts.first(limit)
end
@@ -51,7 +51,7 @@ class PostsController < ApplicationController
render json: (post
.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } })
.merge(viewed: viewed))
.merge(related: post.related(limit: 20), viewed:))
end
# POST /posts