Merge pull request #10060 from tchak/fix-improuve-municipalities-handling-by-ban-api
fix(adress): show postal code on municipalities
This commit is contained in:
commit
124466a6a2
4 changed files with 197 additions and 184 deletions
|
@ -18,11 +18,20 @@ class DataSources::AdresseController < ApplicationController
|
|||
private
|
||||
|
||||
def fetch_results
|
||||
Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 })
|
||||
Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 }, timeout: 3)
|
||||
end
|
||||
|
||||
def format_results(results)
|
||||
results[:features].map do
|
||||
results[:features].flat_map do |feature|
|
||||
if feature[:properties][:type] == 'municipality'
|
||||
departement_code = feature[:properties][:context].split(',').first
|
||||
APIGeoService.commune_postal_codes(departement_code, feature[:properties][:citycode]).map do |postcode|
|
||||
feature.deep_merge(properties: { postcode:, label: "#{feature[:properties][:label]} (#{postcode})" })
|
||||
end
|
||||
else
|
||||
feature
|
||||
end
|
||||
end.map do
|
||||
{
|
||||
label: _1[:properties][:label],
|
||||
value: _1[:properties][:label],
|
||||
|
|
|
@ -31,7 +31,7 @@ class DataSources::CommuneController < ApplicationController
|
|||
nom: name,
|
||||
boost: 'population',
|
||||
limit: 100
|
||||
})
|
||||
}, timeout: 3)
|
||||
end
|
||||
|
||||
def fetch_by_postal_code(postal_code)
|
||||
|
@ -39,8 +39,8 @@ class DataSources::CommuneController < ApplicationController
|
|||
type: 'commune-actuelle,arrondissement-municipal',
|
||||
codePostal: postal_code,
|
||||
boost: 'population',
|
||||
limit: 20
|
||||
})
|
||||
limit: 50
|
||||
}, timeout: 3)
|
||||
end
|
||||
|
||||
def postal_code?(string)
|
||||
|
|
|
@ -81,6 +81,10 @@ class APIGeoService
|
|||
communes(departement_code).find { _1[:name] == name }&.dig(:code)
|
||||
end
|
||||
|
||||
def commune_postal_codes(departement_code, code)
|
||||
communes(departement_code).filter { _1[:code] == code }.map { _1[:postal_code] }
|
||||
end
|
||||
|
||||
def parse_ban_address(feature)
|
||||
return unless ban_address_schema.valid?(feature)
|
||||
|
||||
|
|
358
spec/fixtures/cassettes/The_user/fill_a_dossier.yml
vendored
358
spec/fixtures/cassettes/The_user/fill_a_dossier.yml
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue