diff --git a/.app_version b/.app_version index ebf55b3d..5daaa7ba 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.13.6 +0.13.7 diff --git a/CHANGELOG.md b/CHANGELOG.md index 621af4c4..1c7d1364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.13.7] — 2024-09-15 + +### Added + +- `GET /api/v1/points` response now will include `X-Total-Pages` and `X-Current-Page` headers to make it easier to work with the endpoint + + ## [0.13.6] — 2024-09-13 ### Fixed diff --git a/app/controllers/api/v1/points_controller.rb b/app/controllers/api/v1/points_controller.rb index d6a32c8d..6a7d2e59 100644 --- a/app/controllers/api/v1/points_controller.rb +++ b/app/controllers/api/v1/points_controller.rb @@ -12,6 +12,9 @@ class Api::V1::PointsController < ApiController .page(params[:page]) .per(params[:per_page] || 100) + response.set_header('X-Current-Page', points.current_page) + response.set_header('X-Total-Pages', points.total_pages) + render json: points end diff --git a/app/controllers/points_controller.rb b/app/controllers/points_controller.rb index fa9708d4..76bb9f24 100644 --- a/app/controllers/points_controller.rb +++ b/app/controllers/points_controller.rb @@ -16,7 +16,6 @@ class PointsController < ApplicationController @start_at = Time.zone.at(start_at) @end_at = Time.zone.at(end_at) - @points_number = @points.except(:limit, :offset).size @imports = current_user.imports.order(created_at: :desc) end diff --git a/app/views/points/index.html.erb b/app/views/points/index.html.erb index 8837a00d..7f7d7fd9 100644 --- a/app/views/points/index.html.erb +++ b/app/views/points/index.html.erb @@ -49,8 +49,8 @@
<%= f.submit "Delete Selected", class: "px-4 py-2 bg-red-500 text-white rounded-md", data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" } %> -
- <%= @points_number %> points found +
+ <%= page_entries_info @points, entry_name: 'point' %>
Order by: diff --git a/spec/requests/api/v1/points_spec.rb b/spec/requests/api/v1/points_spec.rb index 2378df2a..fa10c5c8 100644 --- a/spec/requests/api/v1/points_spec.rb +++ b/spec/requests/api/v1/points_spec.rb @@ -32,5 +32,14 @@ RSpec.describe 'Api::V1::Points', type: :request do expect(json_response.size).to eq(10) end + + it 'returns a list of points with pagination headers' do + get api_v1_points_url(api_key: user.api_key, page: 2, per_page: 10) + + expect(response).to have_http_status(:ok) + + expect(response.headers['X-Current-Page']).to eq(2) + expect(response.headers['X-Total-Pages']).to eq(15) + end end end