diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cbed580..fbc78392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Points imported from Google Location History (mobile devise) now have correct timestamps +### Changed + +- `GET /api/v1/points?slim=true` now returns `id` attribute for each point + # [0.14.5] - 2024-09-28 ### Fixed diff --git a/app/controllers/api/v1/points_controller.rb b/app/controllers/api/v1/points_controller.rb index 6079b60c..a7d1a622 100644 --- a/app/controllers/api/v1/points_controller.rb +++ b/app/controllers/api/v1/points_controller.rb @@ -11,7 +11,7 @@ class Api::V1::PointsController < ApiController .order(:timestamp) .page(params[:page]) .per(params[:per_page] || 100) - + serialized_points = points.map { |point| point_serializer.new(point).call } response.set_header('X-Current-Page', points.current_page.to_s) @@ -30,6 +30,6 @@ class Api::V1::PointsController < ApiController private def point_serializer - params[:slim] ? SlimPointSerializer : PointSerializer + params[:slim] == 'true' ? SlimPointSerializer : PointSerializer end end diff --git a/app/serializers/slim_point_serializer.rb b/app/serializers/slim_point_serializer.rb index b9b28d3c..9d6a0450 100644 --- a/app/serializers/slim_point_serializer.rb +++ b/app/serializers/slim_point_serializer.rb @@ -7,7 +7,8 @@ class SlimPointSerializer def call { - latitude: point.latitude, + id: point.id, + latitude: point.latitude, longitude: point.longitude, timestamp: point.timestamp } diff --git a/spec/requests/api/v1/points_spec.rb b/spec/requests/api/v1/points_spec.rb index 32839871..d8ac15c4 100644 --- a/spec/requests/api/v1/points_spec.rb +++ b/spec/requests/api/v1/points_spec.rb @@ -46,13 +46,13 @@ RSpec.describe 'Api::V1::Points', type: :request do context 'when slim version of points is requested' do it 'renders a successful response' do - get api_v1_points_url(api_key: user.api_key, slim: true) + get api_v1_points_url(api_key: user.api_key, slim: 'true') expect(response).to be_successful end it 'returns a list of points' do - get api_v1_points_url(api_key: user.api_key, slim: true) + get api_v1_points_url(api_key: user.api_key, slim: 'true') expect(response).to have_http_status(:ok) @@ -62,7 +62,7 @@ RSpec.describe 'Api::V1::Points', type: :request do end it 'returns a list of points with pagination' do - get api_v1_points_url(api_key: user.api_key, slim: true, page: 2, per_page: 10) + get api_v1_points_url(api_key: user.api_key, slim: 'true', page: 2, per_page: 10) expect(response).to have_http_status(:ok) @@ -72,7 +72,7 @@ RSpec.describe 'Api::V1::Points', type: :request do end it 'returns a list of points with pagination headers' do - get api_v1_points_url(api_key: user.api_key, slim: true, page: 2, per_page: 10) + get api_v1_points_url(api_key: user.api_key, slim: 'true', page: 2, per_page: 10) expect(response).to have_http_status(:ok) @@ -81,7 +81,7 @@ RSpec.describe 'Api::V1::Points', type: :request do end it 'returns a list of points with slim attributes' do - get api_v1_points_url(api_key: user.api_key, slim: true) + get api_v1_points_url(api_key: user.api_key, slim: 'true') expect(response).to have_http_status(:ok)