chore(service): limit geocoding area to INSEE code commune
This commit is contained in:
parent
1ce4d17ad5
commit
578f19b000
2 changed files with 13 additions and 8 deletions
|
@ -5,14 +5,19 @@ class APIEntreprise::ServiceJob < APIEntreprise::Job
|
|||
service_params = APIEntreprise::ServiceAdapter.new(service.siret, service_id).to_params
|
||||
service.etablissement_infos = service_params
|
||||
|
||||
point = Geocoder.search(service_params[:adresse]).first
|
||||
code_insee = service.etablissement_infos['code_insee_localite']
|
||||
if code_insee.present?
|
||||
service.departement = CodeInsee.new(code_insee).to_departement
|
||||
end
|
||||
|
||||
if service_params[:adresse].present?
|
||||
point = Geocoder.search(service_params[:adresse], params: { citycode: code_insee, limit: 1 }).first
|
||||
|
||||
service.etablissement_lat = point&.latitude
|
||||
service.etablissement_lng = point&.longitude
|
||||
|
||||
code_insee = service.etablissement_infos['code_insee_localite']
|
||||
if code_insee
|
||||
service.departement = CodeInsee.new(code_insee).to_departement
|
||||
else
|
||||
service.etablissement_lat = nil
|
||||
service.etablissement_lng = nil
|
||||
end
|
||||
|
||||
service.save!
|
||||
|
|
|
@ -14,7 +14,7 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
|||
|
||||
Geocoder.configure(lookup: :ban_data_gouv_fr, use_https: true)
|
||||
|
||||
stub_request(:get, "https://api-adresse.data.gouv.fr/search/?q=#{adresse}")
|
||||
stub_request(:get, "https://api-adresse.data.gouv.fr/search/?citycode=75112&limit=1&q=#{adresse}")
|
||||
.to_return(body: geocoder_body, status: status)
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,7 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
|||
geocoder_response = JSON.parse(geocoder_body)
|
||||
geocoder_response["features"] = []
|
||||
|
||||
stub_request(:get, "https://api-adresse.data.gouv.fr/search/?q=#{adresse}")
|
||||
stub_request(:get, "https://api-adresse.data.gouv.fr/search/?citycode=75112&limit=1&q=#{adresse}")
|
||||
.to_return(body: JSON.generate(geocoder_response), status: status)
|
||||
|
||||
subject
|
||||
|
|
Loading…
Reference in a new issue