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:
2026-06-26 20:36:16 +02:00
parent e11c7d24a4
commit bc2e056b68
2 changed files with 31 additions and 1 deletions
+4 -1
View File
@@ -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