diff --git a/app/services/api_geo_service.rb b/app/services/api_geo_service.rb index 5a8e0bcc1..c12804c2a 100644 --- a/app/services/api_geo_service.rb +++ b/app/services/api_geo_service.rb @@ -140,7 +140,7 @@ class APIGeoService postal_code = address[:code_postal] city_name_fallback = address[:commune] city_code = address[:code_insee] - departement_code, region_code = if postal_code.present? && city_code.present? + department_code, region_code = if postal_code.present? && city_code.present? commune = communes_by_postal_code(postal_code).find { _1[:code] == city_code } if commune.present? [commune[:departement_code], commune[:region_code]] @@ -149,15 +149,18 @@ class APIGeoService end end + department_name = departement_name(department_code) { street_number: address[:numero_voie], street_name: address[:libelle_voie], street_address: address[:libelle_voie].present? ? [address[:numero_voie], address[:type_voie], address[:libelle_voie]].compact.join(' ') : nil, postal_code: postal_code.presence || '', - city_name: safely_normalize_city_name(departement_code, city_code, city_name_fallback), + city_name: safely_normalize_city_name(department_code, city_code, city_name_fallback), city_code: city_code.presence || '', - departement_code:, - departement_name: departement_name(departement_code), + departement_code: department_code, + department_code:, + departement_name: department_name, + department_name:, region_code:, region_name: region_name(region_code) } @@ -167,7 +170,7 @@ class APIGeoService postal_code = address[:postalCode] city_name_fallback = address[:cityName] city_code = address[:cityCode] - departement_code, region_code = if postal_code.present? && city_code.present? + department_code, region_code = if postal_code.present? && city_code.present? commune = communes_by_postal_code(postal_code).find { _1[:code] == city_code } if commune.present? [commune[:departement_code], commune[:region_code]] @@ -175,16 +178,19 @@ class APIGeoService [] end end + department_name = departement_name(department_code) { street_number: address[:streetNumber], street_name: address[:streetName], street_address: address[:streetAddress], postal_code: postal_code.presence || '', - city_name: safely_normalize_city_name(departement_code, city_code, city_name_fallback), + city_name: safely_normalize_city_name(department_code, city_code, city_name_fallback), city_code: city_code.presence || '', - departement_code:, - departement_name: departement_name(departement_code), + departement_code: department_code, + department_code:, + departement_name: department_name, + department_name:, region_code:, region_name: region_name(region_code) } @@ -194,7 +200,7 @@ class APIGeoService postal_code = etablissement.code_postal city_name_fallback = etablissement.localite.presence || '' city_code = etablissement.code_insee_localite - departement_code, region_code = if postal_code.present? && city_code.present? + department_code, region_code = if postal_code.present? && city_code.present? commune = communes_by_postal_code(postal_code).find { _1[:code] == city_code } if commune.present? [commune[:departement_code], commune[:region_code]] @@ -203,15 +209,19 @@ class APIGeoService end end + department_name = departement_name(department_code) + { street_number: etablissement.numero_voie, street_name: etablissement.nom_voie, street_address: etablissement.nom_voie.present? ? [etablissement.numero_voie, etablissement.type_voie, etablissement.nom_voie].compact.join(' ') : nil, postal_code: postal_code.presence || '', - city_name: safely_normalize_city_name(departement_code, city_code, city_name_fallback), + city_name: safely_normalize_city_name(department_code, city_code, city_name_fallback), city_code: city_code.presence || '', - departement_code:, - departement_name: departement_name(departement_code), + departement_code: department_code, + department_code:, + departement_name: department_name, + department_name:, region_code:, region_name: region_name(region_code) } diff --git a/spec/controllers/champs/rna_controller_spec.rb b/spec/controllers/champs/rna_controller_spec.rb index a4a09377b..9b149e8dc 100644 --- a/spec/controllers/champs/rna_controller_spec.rb +++ b/spec/controllers/champs/rna_controller_spec.rb @@ -126,7 +126,9 @@ describe Champs::RNAController, type: :controller do "city_code" => "75108", "city_name" => "Paris", "departement_code" => nil, # might seem broken lookup, but no, it's anonymized + "department_code" => nil, # might seem broken lookup, but no, it's anonymized "departement_name" => nil, + "department_name" => nil, "postal_code" => "75009", "region_code" => nil, "region_name" => nil, diff --git a/spec/models/champs/rnf_champ_spec.rb b/spec/models/champs/rnf_champ_spec.rb index d44e47fe4..f83759a83 100644 --- a/spec/models/champs/rnf_champ_spec.rb +++ b/spec/models/champs/rnf_champ_spec.rb @@ -109,7 +109,9 @@ describe Champs::RNFChamp, type: :model do :city_name => "Paris 15e Arrondissement", :city_code => "75115", :departement_code => "75", + :department_code => "75", :departement_name => "Paris", + :department_name => "Paris", :region_code => "11", :region_name => "Île-de-France" } diff --git a/spec/tasks/maintenance/populate_rna_json_value_task_spec.rb b/spec/tasks/maintenance/populate_rna_json_value_task_spec.rb index 9103b9a95..bdb3fd559 100644 --- a/spec/tasks/maintenance/populate_rna_json_value_task_spec.rb +++ b/spec/tasks/maintenance/populate_rna_json_value_task_spec.rb @@ -29,7 +29,9 @@ module Maintenance "city_name" => "Paris", "city_code" => "75108", "departement_code" => nil, + "department_code" => nil, "departement_name" => nil, + "department_name" => nil, "region_code" => nil, "region_name" => nil }) diff --git a/spec/tasks/maintenance/populate_rnf_json_value_task_spec.rb b/spec/tasks/maintenance/populate_rnf_json_value_task_spec.rb index de66e0033..a71eb25ad 100644 --- a/spec/tasks/maintenance/populate_rnf_json_value_task_spec.rb +++ b/spec/tasks/maintenance/populate_rnf_json_value_task_spec.rb @@ -62,7 +62,9 @@ module Maintenance "city_name" => "Paris 15e Arrondissement", "city_code" => "75115", "departement_code" => "75", + "department_code" => "75", "departement_name" => "Paris", + "department_name" => "Paris", "region_code" => "11", "region_name" => "Île-de-France" }) @@ -86,7 +88,9 @@ module Maintenance "city_name" => "Paris 15e Arrondissement", "city_code" => "75115", "departement_code" => "75", + "department_code" => "75", "departement_name" => "Paris", + "department_name" => "Paris", "region_code" => "11", "region_name" => "Île-de-France" }) diff --git a/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb b/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb index 76759ed40..f5e1a29a6 100644 --- a/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb +++ b/spec/tasks/maintenance/populate_siret_value_json_task_spec.rb @@ -23,7 +23,9 @@ module Maintenance "street_number" => "6", "street_address" => "6 RUE RAOUL NORDLING", "departement_code" => "92", - "departement_name" => "Hauts-de-Seine" + "department_code" => "92", + "departement_name" => "Hauts-de-Seine", + "department_name" => "Hauts-de-Seine" }) end end