diff --git a/CHANGELOG.md b/CHANGELOG.md index 19dcf086..9b5c7252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/). # 0.19.4 - 2024-12-10 +⚠️ This release introduces a breaking change. ⚠️ + +The `GET /api/v1/trips/:id/photos` endpoint now returns a different structure of the response: + +```diff +{ + id: 1, + latitude: 10, + longitude: 10, + localDateTime: "2024-01-01T00:00:00Z", + originalFileName: "photo.jpg", + city: "Berlin", + state: "Berlin", + country: "Germany", + type: "image", ++ orientation: "portrait", + source: "photoprism" +} +``` + ### Fixed - Fixed a bug where the Photoprism photos were not being shown on the trip page. @@ -16,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - A link to the Photoprism photos on the trip page if there are any. - A `orientation` field in the Api::PhotoSerializer, hence the `GET /api/v1/photos` endpoint now includes the orientation of the photo. Valid values are `portrait` and `landscape`. +- Examples for the `type`, `orientation` and `source` fields in the `GET /api/v1/photos` endpoint in the Swagger UI. # 0.19.3 - 2024-12-06 diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb index a0eb6e08..93657bd4 100644 --- a/app/controllers/map_controller.rb +++ b/app/controllers/map_controller.rb @@ -36,9 +36,7 @@ class MapController < ApplicationController @distance ||= 0 @coordinates.each_cons(2) do - @distance += Geocoder::Calculations.distance_between( - [_1[0], _1[1]], [_2[0], _2[1]], units: DISTANCE_UNIT - ) + @distance += DistanceCalculator.new([_1[0], _1[1]], [_2[0], _2[1]]).call end @distance.round(1) diff --git a/app/models/trip.rb b/app/models/trip.rb index e75103c2..4a2b0302 100644 --- a/app/models/trip.rb +++ b/app/models/trip.rb @@ -35,6 +35,8 @@ class Trip < ApplicationRecord vertical_photos = photos.select { |photo| photo[:orientation] == 'portrait' } horizontal_photos = photos.select { |photo| photo[:orientation] == 'landscape' } + # this is ridiculous, but I couldn't find my way around frontend + # to show all photos in the same height vertical_photos.count > horizontal_photos.count ? vertical_photos : horizontal_photos end @@ -42,11 +44,7 @@ class Trip < ApplicationRecord distance = 0 points.each_cons(2) do |point1, point2| - distance_between = Geocoder::Calculations.distance_between( - point1.to_coordinates, point2.to_coordinates, units: ::DISTANCE_UNIT - ) - - distance += distance_between + distance += DistanceCalculator.new(point1, point2).call end self.distance = distance.round diff --git a/app/models/visit.rb b/app/models/visit.rb index 2ca496ab..bfd5b3d0 100644 --- a/app/models/visit.rb +++ b/app/models/visit.rb @@ -28,7 +28,9 @@ class Visit < ApplicationRecord def default_radius return area&.radius if area.present? - radius = points.map { Geocoder::Calculations.distance_between(center, [_1.latitude, _1.longitude]) }.max + radius = points.map do |point| + DistanceCalculator.new(center, [point.latitude, point.longitude]).call + end.max radius && radius >= 15 ? radius : 15 end diff --git a/spec/models/trip_spec.rb b/spec/models/trip_spec.rb index 0638d781..032185bd 100644 --- a/spec/models/trip_spec.rb +++ b/spec/models/trip_spec.rb @@ -116,7 +116,9 @@ RSpec.describe Trip, type: :model do end it 'returns the photos' do - expect(trip.photo_previews).to eq(expected_photos) + expect(trip.photo_previews).to include(expected_photos[0]) + expect(trip.photo_previews).to include(expected_photos[1]) + expect(trip.photo_previews.size).to eq(2) end end end diff --git a/spec/swagger/api/v1/photos_controller_spec.rb b/spec/swagger/api/v1/photos_controller_spec.rb index 2c375ef1..d7c4de4c 100644 --- a/spec/swagger/api/v1/photos_controller_spec.rb +++ b/spec/swagger/api/v1/photos_controller_spec.rb @@ -110,9 +110,9 @@ RSpec.describe 'Api::V1::PhotosController', type: :request do city: { type: :string }, state: { type: :string }, country: { type: :string }, - type: { type: :string }, - orientation: { type: :string }, - source: { type: :string } + type: { type: :string, enum: %w[image video] }, + orientation: { type: :string, enum: %w[portrait landscape] }, + source: { type: :string, enum: %w[immich photoprism] } }, required: %w[id latitude longitude localDateTime originalFileName city state country type source] } @@ -143,9 +143,9 @@ RSpec.describe 'Api::V1::PhotosController', type: :request do city: { type: :string }, state: { type: :string }, country: { type: :string }, - type: { type: :string }, - source: { type: :string }, - orientation: { type: :string, enum: %w[portrait landscape] } + type: { type: :string, enum: %w[image video] }, + orientation: { type: :string, enum: %w[portrait landscape] }, + source: { type: :string, enum: %w[immich photoprism] } } let(:id) { '7fe486e3-c3ba-4b54-bbf9-1281b39ed15c' } diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index 49d8ef24..f6072149 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -366,10 +366,19 @@ paths: type: string type: type: string + enum: + - image + - video orientation: type: string + enum: + - portrait + - landscape source: type: string + enum: + - immich + - photoprism required: - id - latitude @@ -431,13 +440,19 @@ paths: type: string type: type: string - source: - type: string + enum: + - image + - video orientation: type: string enum: - portrait - landscape + source: + type: string + enum: + - immich + - photoprism '404': description: photo not found "/api/v1/points":