diff --git a/.app_version b/.app_version index d9df1bbc..af88ba82 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.11.0 +0.11.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d71148a..28c6d3de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +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.11.1] — 2024-08-21 + +### Changed + +- `/api/v1/points` endpoint now returns 100 points by default. You can specify the number of points to return by passing the `per_page` query parameter. Example: `/api/v1/points?per_page=50` will return 50 points. Also, `page` query parameter is now available to paginate the results. Example: `/api/v1/points?per_page=50&page=2` will return the second page of 50 points. + ## [0.11.0] — 2024-08-21 ### Added diff --git a/app/controllers/api/v1/points_controller.rb b/app/controllers/api/v1/points_controller.rb index 88215cb1..61c250b2 100644 --- a/app/controllers/api/v1/points_controller.rb +++ b/app/controllers/api/v1/points_controller.rb @@ -8,7 +8,12 @@ class Api::V1::PointsController < ApplicationController start_at = params[:start_at]&.to_datetime&.to_i end_at = params[:end_at]&.to_datetime&.to_i || Time.zone.now.to_i - points = current_api_user.tracked_points.where(timestamp: start_at..end_at) + points = current_api_user + .tracked_points + .where(timestamp: start_at..end_at) + .order(:timestamp) + .page(params[:page]) + .per(params[:per_page] || 100) render json: points end diff --git a/spec/requests/api/v1/points_spec.rb b/spec/requests/api/v1/points_spec.rb new file mode 100644 index 00000000..2378df2a --- /dev/null +++ b/spec/requests/api/v1/points_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::Points', type: :request do + let!(:user) { create(:user) } + let!(:points) { create_list(:point, 150, user:) } + + describe 'GET /index' do + it 'renders a successful response' do + get api_v1_points_url(api_key: user.api_key) + + expect(response).to be_successful + end + + it 'returns a list of points' do + get api_v1_points_url(api_key: user.api_key) + + expect(response).to have_http_status(:ok) + + json_response = JSON.parse(response.body) + + expect(json_response.size).to eq(100) + end + + it 'returns a list of points with pagination' do + get api_v1_points_url(api_key: user.api_key, page: 2, per_page: 10) + + expect(response).to have_http_status(:ok) + + json_response = JSON.parse(response.body) + + expect(json_response.size).to eq(10) + end + end +end