diff --git a/.app_version b/.app_version index 4240544f..03035cdd 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.22.4 +0.22.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc13f47..f2622d79 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.22.5 - 2025-01-20 + +### Added + +- `POST /api/v1/points/create` endpoint added to create points from a file. + # 0.22.4 - 2025-01-20 ### Added diff --git a/config/routes.rb b/config/routes.rb index 0befcca4..9e1384a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,7 +67,7 @@ Rails.application.routes.draw do get 'settings', to: 'settings#index' resources :areas, only: %i[index create update destroy] - resources :points, only: %i[index destroy update] + resources :points, only: %i[index create update destroy] resources :visits, only: %i[update] resources :stats, only: :index diff --git a/spec/swagger/api/v1/points_controller_spec.rb b/spec/swagger/api/v1/points_controller_spec.rb index d4ff924c..d3dc087c 100644 --- a/spec/swagger/api/v1/points_controller_spec.rb +++ b/spec/swagger/api/v1/points_controller_spec.rb @@ -67,6 +67,87 @@ describe 'Points API', type: :request do run_test! end end + + post 'Creates a batch of points' do + request_body_example value: { + locations: [ + { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [-122.40530871, 37.74430413] + }, + properties: { + timestamp: '2025-01-17T21:03:01Z', + horizontal_accuracy: 5, + vertical_accuracy: -1, + altitude: 0, + speed: 92.088, + speed_accuracy: 0, + course: 27.07, + course_accuracy: 0, + track_id: '799F32F5-89BB-45FB-A639-098B1B95B09F', + device_id: '8D5D4197-245B-4619-A88B-2049100ADE46' + } + } + ] + } + tags 'Batches' + consumes 'application/json' + parameter name: :locations, in: :body, schema: { + type: :object, + properties: { + type: { type: :string }, + geometry: { + type: :object, + properties: { + type: { type: :string }, + coordinates: { type: :array, items: { type: :number } } + } + }, + properties: { + type: :object, + properties: { + timestamp: { type: :string }, + horizontal_accuracy: { type: :number }, + vertical_accuracy: { type: :number }, + altitude: { type: :number }, + speed: { type: :number }, + speed_accuracy: { type: :number }, + course: { type: :number }, + course_accuracy: { type: :number }, + track_id: { type: :string }, + device_id: { type: :string } + } + } + }, + required: %w[geometry properties] + } + + parameter name: :api_key, in: :query, type: :string, required: true, description: 'API Key' + + response '200', 'Batch of points being processed' do + let(:file_path) { 'spec/fixtures/files/points/geojson_example.json' } + let(:file) { File.open(file_path) } + let(:json) { JSON.parse(file.read) } + let(:params) { json } + let(:locations) { params['locations'] } + let(:api_key) { create(:user).api_key } + + run_test! + end + + response '401', 'Unauthorized' do + let(:file_path) { 'spec/fixtures/files/points/geojson_example.json' } + let(:file) { File.open(file_path) } + let(:json) { JSON.parse(file.read) } + let(:params) { json } + let(:locations) { params['locations'] } + let(:api_key) { 'invalid_api_key' } + + run_test! + end + end end path '/api/v1/points/{id}' do diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index beed0840..d40786d2 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -696,6 +696,87 @@ paths: type: string visit_id: type: string + post: + summary: Creates a batch of points + tags: + - Batches + parameters: + - name: api_key + in: query + required: true + description: API Key + schema: + type: string + responses: + '200': + description: Batch of points being processed + '401': + description: Unauthorized + requestBody: + content: + application/json: + schema: + type: object + properties: + type: + type: string + geometry: + type: object + properties: + type: + type: string + coordinates: + type: array + items: + type: number + properties: + type: object + properties: + timestamp: + type: string + horizontal_accuracy: + type: number + vertical_accuracy: + type: number + altitude: + type: number + speed: + type: number + speed_accuracy: + type: number + course: + type: number + course_accuracy: + type: number + track_id: + type: string + device_id: + type: string + required: + - geometry + - properties + examples: + '0': + summary: Creates a batch of points + value: + locations: + - type: Feature + geometry: + type: Point + coordinates: + - -122.40530871 + - 37.74430413 + properties: + timestamp: '2025-01-17T21:03:01Z' + horizontal_accuracy: 5 + vertical_accuracy: -1 + altitude: 0 + speed: 92.088 + speed_accuracy: 0 + course: 27.07 + course_accuracy: 0 + track_id: 799F32F5-89BB-45FB-A639-098B1B95B09F + device_id: 8D5D4197-245B-4619-A88B-2049100ADE46 "/api/v1/points/{id}": delete: summary: Deletes a point