feat(rna): also store rna title

This commit is contained in:
mfo 2024-11-15 09:33:42 +01:00
parent a9237bf7f1
commit cfd568b98d
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
5 changed files with 17 additions and 4 deletions

View file

@ -13,6 +13,10 @@ class Champs::RNAChamp < Champ
data&.dig("association_titre") data&.dig("association_titre")
end end
def update_with_external_data!(data:)
update!(data:, value_json: extract_value_json(data:))
end
def identifier def identifier
title.present? ? "#{value} (#{title})" : value title.present? ? "#{value} (#{title})" : value
end end
@ -41,4 +45,11 @@ class Champs::RNAChamp < Champ
city_code: address["code_insee"] city_code: address["code_insee"]
}.with_indifferent_access }.with_indifferent_access
end end
private
def extract_value_json(data:)
h = APIGeoService.parse_rna_address(data['adresse'])
h.merge(title: data['association_titre'])
end
end end

View file

@ -12,7 +12,7 @@ module RNAChampAssociationFetchableConcern
return clear_association!(:invalid) unless valid_champ_value? return clear_association!(:invalid) unless valid_champ_value?
return clear_association!(:not_found) if (data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params).blank? return clear_association!(:not_found) if (data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params).blank?
update!(data:, value_json: APIGeoService.parse_rna_address(data['adresse'])) update_with_external_data!(data:)
rescue APIEntreprise::API::Error, APIEntrepriseToken::TokenError => error rescue APIEntreprise::API::Error, APIEntrepriseToken::TokenError => error
if APIEntrepriseService.service_unavailable_error?(error, target: :djepva) if APIEntrepriseService.service_unavailable_error?(error, target: :djepva)
clear_association!(:network_error) clear_association!(:network_error)

View file

@ -14,7 +14,7 @@ module Maintenance
return if champ&.dossier&.procedure&.id.blank? return if champ&.dossier&.procedure&.id.blank?
data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params
return if data.blank? return if data.blank?
champ.update(value_json: APIGeoService.parse_rna_address(data['adresse'])) champ.update_with_external_data!(data:)
rescue URI::InvalidURIError rescue URI::InvalidURIError
# some Champs::RNAChamp contain spaces which raise this error # some Champs::RNAChamp contain spaces which raise this error
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound

View file

@ -134,7 +134,8 @@ describe Champs::RNAController, type: :controller do
"region_name" => nil, "region_name" => nil,
"street_address" => "33 rue de Modagor", "street_address" => "33 rue de Modagor",
"street_name" => "de Modagor", "street_name" => "de Modagor",
"street_number" => "33" "street_number" => "33",
"title" => "LA PRÉVENTION ROUTIERE"
}) })
end end
end end

View file

@ -33,7 +33,8 @@ module Maintenance
"departement_name" => nil, "departement_name" => nil,
"department_name" => nil, "department_name" => nil,
"region_code" => nil, "region_code" => nil,
"region_name" => nil "region_name" => nil,
"title" => "LA PRÉVENTION ROUTIERE"
}) })
end end
end end