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,16 +5,21 @@ class APIEntreprise::ServiceJob < APIEntreprise::Job
|
||||||
service_params = APIEntreprise::ServiceAdapter.new(service.siret, service_id).to_params
|
service_params = APIEntreprise::ServiceAdapter.new(service.siret, service_id).to_params
|
||||||
service.etablissement_infos = service_params
|
service.etablissement_infos = service_params
|
||||||
|
|
||||||
point = Geocoder.search(service_params[:adresse]).first
|
|
||||||
|
|
||||||
service.etablissement_lat = point&.latitude
|
|
||||||
service.etablissement_lng = point&.longitude
|
|
||||||
|
|
||||||
code_insee = service.etablissement_infos['code_insee_localite']
|
code_insee = service.etablissement_infos['code_insee_localite']
|
||||||
if code_insee
|
if code_insee.present?
|
||||||
service.departement = CodeInsee.new(code_insee).to_departement
|
service.departement = CodeInsee.new(code_insee).to_departement
|
||||||
end
|
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
|
||||||
|
else
|
||||||
|
service.etablissement_lat = nil
|
||||||
|
service.etablissement_lng = nil
|
||||||
|
end
|
||||||
|
|
||||||
service.save!
|
service.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
||||||
|
|
||||||
Geocoder.configure(lookup: :ban_data_gouv_fr, use_https: true)
|
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)
|
.to_return(body: geocoder_body, status: status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ RSpec.describe APIEntreprise::ServiceJob, type: :job do
|
||||||
geocoder_response = JSON.parse(geocoder_body)
|
geocoder_response = JSON.parse(geocoder_body)
|
||||||
geocoder_response["features"] = []
|
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)
|
.to_return(body: JSON.generate(geocoder_response), status: status)
|
||||||
|
|
||||||
subject
|
subject
|
||||||
|
|
Loading…
Reference in a new issue