#59 関聯投稿一覧の追加
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user