feat: add has_next and has_prev to paginated posts response
Clients no longer need to compute page boundaries themselves; the API now returns boolean flags indicating whether more pages exist in each direction. Includes tests for first, middle, and last page.
This commit is contained in:
@@ -101,10 +101,13 @@ module Volumen
|
||||
page = positive_int(params["page"], 1)
|
||||
limit = positive_int(params["limit"], 20).clamp(1, 100)
|
||||
offset = (page - 1) * limit
|
||||
total = posts.length
|
||||
{
|
||||
"page" => page,
|
||||
"page_size" => limit,
|
||||
"total" => posts.length,
|
||||
"total" => total,
|
||||
"has_next" => offset + limit < total,
|
||||
"has_prev" => page > 1,
|
||||
"posts" => posts[offset, limit].to_a.map(&:summary)
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user