Fix some swagger specs and remove unused code

This commit is contained in:
Eugene Burmakin 2024-12-16 15:42:26 +01:00
parent 81dc03f7c9
commit 2ee7bb74a3
6 changed files with 32 additions and 81 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [Unreleased]
### Added
- `GET /api/v1/points/tracked_months` endpoint added to get list of tracked years and months.
- `GET /api/v1/countries/visited_cities` endpoint added to get list of visited cities.
### Fixed
- A point popup is no longer closes when hovering over a polyline. #536

View file

@ -16,15 +16,7 @@ class Api::V1::Countries::VisitedCitiesController < ApiController
private
def validate_params
missing_params = %i[start_at end_at].select { |param| params[param].blank? }
if missing_params.any?
render json: {
error: "Missing required parameters: #{missing_params.join(', ')}"
}, status: :bad_request and return
end
params.permit(:start_at, :end_at)
def required_params
%i[start_at end_at]
end
end

View file

@ -15,4 +15,20 @@ class ApiController < ApplicationController
def current_api_user
@current_api_user ||= User.find_by(api_key: params[:api_key])
end
def validate_params
missing_params = required_params.select { |param| params[param].blank? }
if missing_params.any?
render json: {
error: "Missing required parameters: #{missing_params.join(', ')}"
}, status: :bad_request and return
end
params.permit(*required_params)
end
def required_params
[]
end
end

View file

@ -1,8 +1,6 @@
# frozen_string_literal: true
class CountriesAndCities
MIN_MINUTES_SPENT_IN_CITY = 30 # You can adjust this value as needed
CountryData = Struct.new(:country, :cities, keyword_init: true)
CityData = Struct.new(:city, :points, :timestamp, :stayed_for, keyword_init: true)
@ -40,7 +38,7 @@ class CountriesAndCities
end
def build_city_data(city, points_count, timestamps, duration)
return nil if duration < MIN_MINUTES_SPENT_IN_CITY
return nil if duration < ::MIN_MINUTES_SPENT_IN_CITY
CityData.new(
city: city,

View file

@ -1,61 +0,0 @@
<%= sidebar_distance(@distance) %> <%= sidebar_points(@points) %>
<div id='years-nav'>
<div class="dropdown">
<div tabindex="0" role="button" class="btn">Select year</div>
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
<% current_user.years_tracked.each do |year| %>
<li><%= link_to year, map_url(year_timespan(year).merge(year: year, import_id: params[:import_id])) %></li>
<% end %>
</ul>
</div>
<% @years.each do |year| %>
<h3 class='text-xl'>
<%= year %>
</h3>
<div class='grid grid-cols-3 gap-3'>
<% (1..12).to_a.each_slice(3) do |months| %>
<% months.each do |month_number| %>
<% if past?(year, month_number) && points_exist?(year, month_number, current_user) %>
<%= link_to Date::ABBR_MONTHNAMES[month_number], map_url(timespan(month_number, year).merge(import_id: params[:import_id])), class: 'btn btn-default' %>
<% else %>
<div class='btn btn-disabled'><%= Date::ABBR_MONTHNAMES[month_number] %></div>
<% end %>
<% end %>
<% end %>
</div>
<% end %>
</div>
<% if REVERSE_GEOCODING_ENABLED && @countries_and_cities&.any? %>
<hr class='my-5'>
<% @countries_and_cities.each do |country| %>
<h2 class="text-lg font-semibold mt-5">
<%= country[:country] %> (<%= country[:cities].count %> cities)
</h2>
<ul class="timeline timeline-vertical">
<% country[:cities].each do |city| %>
<li>
<hr />
<div class="timeline-start"><%= link_to_date(city[:timestamp]) %></div>
<div class="timeline-middle">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="h-5 w-5">
<path
fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
clip-rule="evenodd" />
</svg>
</div>
<div class="timeline-end timeline-box"><%= city[:city] %></div>
<hr />
</li>
<% end %>
</ul>
<% end %>
<% end %>

View file

@ -1,4 +1,5 @@
# spec/swagger/api/v1/countries/visited_cities_controller_spec.rb
# frozen_string_literal: true
require 'swagger_helper'
RSpec.describe 'Api::V1::Countries::VisitedCities', type: :request do
@ -14,16 +15,16 @@ RSpec.describe 'Api::V1::Countries::VisitedCities', type: :request do
type: :string,
format: 'date-time',
required: true,
description: 'Start date and time for the range (ISO 8601 format)',
example: '2023-01-01T00:00:00Z'
description: 'Start date in YYYY-MM-DD format',
example: '2023-01-01'
parameter name: :end_at,
in: :query,
type: :string,
format: 'date-time',
required: true,
description: 'End date and time for the range (ISO 8601 format)',
example: '2023-12-31T23:59:59Z'
description: 'End date in YYYY-MM-DD format',
example: '2023-12-31'
response '200', 'cities found' do
schema type: :object,
@ -70,8 +71,8 @@ RSpec.describe 'Api::V1::Countries::VisitedCities', type: :request do
}
}
let(:start_at) { '2023-01-01T00:00:00Z' }
let(:end_at) { '2023-12-31T23:59:59Z' }
let(:start_at) { '2023-01-01' }
let(:end_at) { '2023-12-31' }
let(:api_key) { create(:user).api_key }
run_test!
end