app/services/digital_address.rb
# Write to DB and generate a new address code
Write to DB and generate a new address code
Write to DB and generate a new address code
def generate_address
    city_name = @geo_query.city.present? ? @geo_query.city : NOT_LISTED
    district_name = @geo_query.district.present? ? @geo_query.district : NOT_LISTED
    region = Region.find_or_create_by(name: @geo_query.region)
    city = region.cities.find_or_create_by(name: city_name)
    district = city.districts.find_or_create_by(name: district_name)
    location = district.locations.find_or_create_by(latitude: @latitude,
                                                     longitude: @longitude)
    if location.present?
      set_address location
      true
    else
      false
    end
  end
def generate_address city_name = @geo_query . city . present? ? @geo_query . city : NOT_LISTED district_name = @geo_query . district . present? ? @geo_query . district : NOT_LISTED region = Region . find_or_create_by ( name : @geo_query . region ) city = region . cities . find_or_create_by ( name : city_name ) district = city . districts . find_or_create_by ( name : district_name ) location = district . locations . find_or_create_by ( latitude : @latitude , longitude : @longitude ) if location . present? set_address location true else false end end
Write to DB and generate a new address code
Write to DB and generate a new address code