From f80b2a1affea9143ffb9b136ea8178cef3ab52a1 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 13 Sep 2025 18:30:26 +0200 Subject: [PATCH] Fix last failing specs --- .../api/v1/maps/hexagons_controller.rb | 32 +++++++++++++++++-- app/services/cache/clean.rb | 4 +-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/maps/hexagons_controller.rb b/app/controllers/api/v1/maps/hexagons_controller.rb index 5fb0a089..5743b0e7 100644 --- a/app/controllers/api/v1/maps/hexagons_controller.rb +++ b/app/controllers/api/v1/maps/hexagons_controller.rb @@ -25,7 +25,35 @@ class Api::V1::Maps::HexagonsController < ApiController return render json: { error: 'No user found' }, status: :not_found unless @target_user return render json: { error: 'No date range specified' }, status: :bad_request unless @start_date && @end_date - points_relation = @target_user.points.where(timestamp: @start_date..@end_date) + # Convert dates to timestamps (handle both string and timestamp formats) + start_timestamp = case @start_date + when String + # Check if it's a numeric string (timestamp) or date string + if @start_date.match?(/^\d+$/) + @start_date.to_i + else + Time.parse(@start_date).to_i + end + when Integer + @start_date + else + @start_date.to_i + end + end_timestamp = case @end_date + when String + # Check if it's a numeric string (timestamp) or date string + if @end_date.match?(/^\d+$/) + @end_date.to_i + else + Time.parse(@end_date).to_i + end + when Integer + @end_date + else + @end_date.to_i + end + + points_relation = @target_user.points.where(timestamp: start_timestamp..end_timestamp) point_count = points_relation.count if point_count.positive? @@ -36,7 +64,7 @@ class Api::V1::Maps::HexagonsController < ApiController WHERE user_id = $1 AND timestamp BETWEEN $2 AND $3", 'bounds_query', - [@target_user.id, @start_date.to_i, @end_date.to_i] + [@target_user.id, start_timestamp, end_timestamp] ).first render json: { diff --git a/app/services/cache/clean.rb b/app/services/cache/clean.rb index e555e6a4..ecbfafed 100644 --- a/app/services/cache/clean.rb +++ b/app/services/cache/clean.rb @@ -36,8 +36,8 @@ class Cache::Clean def delete_countries_cities_cache User.find_each do |user| - Rails.cache.delete("dawarich/user_#{user.id}_countries_visited") - Rails.cache.delete("dawarich/user_#{user.id}_cities_visited") + Rails.cache.delete("dawarich/user_#{user.id}_countries") + Rails.cache.delete("dawarich/user_#{user.id}_cities") end end end