2024-08-05 15:23:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Place < ApplicationRecord
|
2025-03-03 14:50:49 -05:00
|
|
|
include Nearable
|
|
|
|
|
include Distanceable
|
|
|
|
|
|
2024-08-12 16:18:11 -04:00
|
|
|
DEFAULT_NAME = 'Suggested place'
|
2024-08-05 15:23:08 -04:00
|
|
|
|
2025-03-03 14:50:49 -05:00
|
|
|
validates :name, :lonlat, presence: true
|
2024-08-05 15:23:08 -04:00
|
|
|
|
2024-08-12 16:18:11 -04:00
|
|
|
has_many :visits, dependent: :destroy
|
|
|
|
|
has_many :place_visits, dependent: :destroy
|
2025-03-03 14:50:49 -05:00
|
|
|
has_many :suggested_visits, -> { distinct }, through: :place_visits, source: :visit
|
2024-08-05 15:23:08 -04:00
|
|
|
|
2024-09-05 15:01:59 -04:00
|
|
|
enum :source, { manual: 0, photon: 1 }
|
2024-08-05 15:23:08 -04:00
|
|
|
|
2025-03-03 14:50:49 -05:00
|
|
|
def lon
|
|
|
|
|
lonlat.x
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def lat
|
|
|
|
|
lonlat.y
|
|
|
|
|
end
|
|
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
def async_reverse_geocode
|
2025-01-07 07:41:09 -05:00
|
|
|
return unless DawarichSettings.reverse_geocoding_enabled?
|
2024-08-05 15:23:08 -04:00
|
|
|
|
|
|
|
|
ReverseGeocodingJob.perform_later(self.class.to_s, id)
|
|
|
|
|
end
|
2024-08-12 16:18:11 -04:00
|
|
|
|
|
|
|
|
def reverse_geocoded?
|
|
|
|
|
geodata.present?
|
|
|
|
|
end
|
2025-03-08 13:40:28 -05:00
|
|
|
|
|
|
|
|
def osm_id
|
|
|
|
|
geodata['properties']['osm_id']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def osm_key
|
|
|
|
|
geodata['properties']['osm_key']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def osm_value
|
|
|
|
|
geodata['properties']['osm_value']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def osm_type
|
|
|
|
|
geodata['properties']['osm_type']
|
|
|
|
|
end
|
2024-08-05 15:23:08 -04:00
|
|
|
end
|