diff --git a/CHANGELOG.md b/CHANGELOG.md index f8566e4a..b394bef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This release includes a data migration to remove duplicated points from the data - `POST /api/v1/points/create` endpoint added to create points from a file. - An index to guarantee uniqueness of points across `latitude`, `longitude`, `timestamp` and `user_id` values. This is introduced to make sure no duplicates will be created in the database in addition to previously existing validations. +- `GET /api/v1/users/me` endpoint added to get current user. # 0.22.4 - 2025-01-20 diff --git a/Gemfile.lock b/Gemfile.lock index 128bf38f..2f30a734 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,7 @@ GEM byebug (11.1.3) chartkick (5.1.2) coderay (1.1.3) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) connection_pool (2.5.0) content_disposition (1.0.0) crack (1.0.0) @@ -154,7 +154,7 @@ GEM csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) importmap-rails (2.1.0) actionpack (>= 6.0.0) @@ -212,18 +212,18 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.4) - nokogiri (1.18.1) + nokogiri (1.18.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.1-aarch64-linux-gnu) + nokogiri (1.18.2-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.1-arm-linux-gnu) + nokogiri (1.18.2-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.1-arm64-darwin) + nokogiri (1.18.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.1-x86_64-darwin) + nokogiri (1.18.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.1-x86_64-linux-gnu) + nokogiri (1.18.2-x86_64-linux-gnu) racc (~> 1.4) oj (3.16.9) bigdecimal (>= 3.0) @@ -232,7 +232,7 @@ GEM orm_adapter (0.5.0) ostruct (0.6.1) parallel (1.26.3) - parser (3.3.6.0) + parser (3.3.7.0) ast (~> 2.4.1) racc patience_diff (1.2.0) @@ -248,7 +248,7 @@ GEM pry (>= 0.13, < 0.15) pry-rails (0.3.11) pry (>= 0.13.0) - psych (5.2.2) + psych (5.2.3) date stringio public_suffix (6.0.1) @@ -297,11 +297,11 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - rdoc (6.10.0) + rdoc (6.11.0) psych (>= 4.0.0) redis (5.3.0) redis-client (>= 0.22.0) - redis-client (0.23.0) + redis-client (0.23.2) connection_pool regexp_parser (2.10.0) reline (0.6.0) @@ -340,7 +340,7 @@ GEM rswag-ui (2.16.0) actionpack (>= 5.2, < 8.1) railties (>= 5.2, < 8.1) - rubocop (1.69.2) + rubocop (1.70.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -352,7 +352,7 @@ GEM unicode-display_width (>= 2.4.0, < 4.0) rubocop-ast (1.37.0) parser (>= 3.3.1.0) - rubocop-rails (2.28.0) + rubocop-rails (2.29.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.52.0, < 2.0) @@ -369,7 +369,7 @@ GEM logger rack (>= 2.2.4) redis-client (>= 0.22.2) - sidekiq-cron (2.0.1) + sidekiq-cron (2.1.0) cronex (>= 0.13.0) fugit (~> 1.8, >= 1.11.1) globalid (>= 1.0.1) @@ -396,7 +396,7 @@ GEM attr_extras (>= 6.2.4) diff-lcs patience_diff - tailwindcss-rails (3.2.0) + tailwindcss-rails (3.3.0) railties (>= 7.0.0) tailwindcss-ruby tailwindcss-ruby (3.4.17) @@ -413,7 +413,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode (0.4.4.5) - unicode-display_width (3.1.3) + unicode-display_width (3.1.4) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uri (1.0.2) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb new file mode 100644 index 00000000..4fbb3f60 --- /dev/null +++ b/app/controllers/api/v1/users_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Api::V1::UsersController < ApiController + def me + render json: { user: current_api_user } + end +end diff --git a/config/routes.rb b/config/routes.rb index 9e1384a9..9a6a38ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Rails.application.routes.draw do get 'health', to: 'health#index' patch 'settings', to: 'settings#update' get 'settings', to: 'settings#index' + get 'users/me', to: 'users#me' resources :areas, only: %i[index create update destroy] resources :points, only: %i[index create update destroy] diff --git a/spec/requests/api/v1/users_spec.rb b/spec/requests/api/v1/users_spec.rb new file mode 100644 index 00000000..3075a94f --- /dev/null +++ b/spec/requests/api/v1/users_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::Users', type: :request do + describe 'GET /me' do + let(:user) { create(:user) } + let(:headers) { { 'Authorization' => "Bearer #{user.api_key}" } } + + it 'returns http success' do + get '/api/v1/users/me', headers: headers + + expect(response).to have_http_status(:success) + expect(response.body).to include(user.email) + expect(response.body).to include(user.id.to_s) + end + end +end diff --git a/spec/swagger/api/v1/users_controller_spec.rb b/spec/swagger/api/v1/users_controller_spec.rb new file mode 100644 index 00000000..753f4f08 --- /dev/null +++ b/spec/swagger/api/v1/users_controller_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'swagger_helper' + +describe 'Users API', type: :request do + path '/api/v1/users/me' do + get 'Returns the current user' do + tags 'Users' + consumes 'application/json' + security [bearer_auth: []] + parameter name: 'Authorization', in: :header, type: :string, required: true, + description: 'Bearer token in the format: Bearer {api_key}' + + response '200', 'user found' do + let(:user) { create(:user) } + let(:Authorization) { "Bearer #{user.api_key}" } + + schema type: :object, + properties: { + user: { + type: :object, + properties: { + id: { type: :integer }, + email: { type: :string }, + created_at: { type: :string, format: 'date-time' }, + updated_at: { type: :string, format: 'date-time' }, + api_key: { type: :string }, + theme: { type: :string }, + settings: { + type: :object, + properties: { + immich_url: { type: :string }, + route_opacity: { type: :string }, + immich_api_key: { type: :string }, + live_map_enabled: { type: :boolean }, + fog_of_war_meters: { type: :string }, + preferred_map_layer: { type: :string }, + speed_colored_routes: { type: :boolean }, + meters_between_routes: { type: :string }, + points_rendering_mode: { type: :string }, + minutes_between_routes: { type: :string }, + time_threshold_minutes: { type: :string }, + merge_threshold_minutes: { type: :string }, + speed_colored_polylines: { type: :boolean } + } + }, + admin: { type: :boolean } + } + } + } + + after do |example| + example.metadata[:response][:content] = { + 'application/json' => { + example: JSON.parse(response.body) + } + } + end + + run_test! + end + end + end +end diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index d40786d2..7264b64e 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -973,6 +973,23 @@ paths: - totalCountriesVisited - totalCitiesVisited - yearlyStats + "/api/v1/users/me": + get: + summary: Returns the current user + tags: + - Users + security: + - bearer_auth: [] + parameters: + - name: Authorization + in: header + required: true + description: 'Bearer token in the format: Bearer {api_key}' + schema: + type: string + responses: + '200': + description: user found servers: - url: http://{defaultHost} variables: