Merge branch 'master' into fix/visits-notificaton-url

This commit is contained in:
Evgenii Burmakin 2024-09-15 20:58:13 +03:00 committed by GitHub
commit cbaf1956a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 4 deletions

View file

@ -5,7 +5,12 @@ 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-14
## [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
- The Pages point now shows total number of points found for provided date range
## Fixed

View file

@ -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.to_s)
response.set_header('X-Total-Pages', points.total_pages.to_s)
render json: points
end

View file

@ -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

View file

@ -49,8 +49,8 @@
<div class="flex justify-between my-5">
<%= 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?" } %>
<div class="flex justify-center">
<%= @points_number %> points found
<div>
<%= page_entries_info @points, entry_name: 'point' %>
</div>
<div class="flex justify-end">
<span class="mr-2">Order by:</span>

View file

@ -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