Unify #generate_qp with #generate_cadastre
This commit is contained in:
parent
a18af4e616
commit
22beb41240
4 changed files with 12 additions and 21 deletions
|
@ -38,7 +38,7 @@ class Users::CarteController < UsersController
|
|||
@error = true
|
||||
else
|
||||
if @dossier.procedure.module_api_carto.quartiers_prioritaires?
|
||||
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json).values
|
||||
quartiers_prioritaires = ModuleApiCartoService.generate_qp(geo_json)
|
||||
@dossier.quartier_prioritaires.build(quartiers_prioritaires)
|
||||
@data[:quartiersPrioritaires] = quartiers_prioritaires
|
||||
end
|
||||
|
|
|
@ -8,15 +8,8 @@ class CARTO::SGMAP::QuartiersPrioritaires::Adapter
|
|||
end
|
||||
|
||||
def to_params
|
||||
params = {}
|
||||
|
||||
data_source[:features].each do |feature|
|
||||
qp_code = feature[:properties][:code]
|
||||
|
||||
params[qp_code] = feature[:properties]
|
||||
params[qp_code][:geometry] = feature[:geometry]
|
||||
data_source[:features].map do |feature|
|
||||
feature[:properties].merge({ geometry: feature[:geometry] })
|
||||
end
|
||||
|
||||
params
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ class ModuleApiCartoService
|
|||
if dossier.procedure.module_api_carto.quartiers_prioritaires?
|
||||
qp_list = generate_qp(JSON.parse(json_latlngs))
|
||||
|
||||
qp_list.each_value do |qp|
|
||||
qp_list.each do |qp|
|
||||
qp[:dossier_id] = dossier.id
|
||||
qp[:geometry] = qp[:geometry].to_json
|
||||
QuartierPrioritaire.create(qp)
|
||||
|
@ -24,11 +24,11 @@ class ModuleApiCartoService
|
|||
end
|
||||
|
||||
def self.generate_qp(coordinates)
|
||||
coordinates.inject({}) { |acc, coordinate|
|
||||
acc.merge CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(
|
||||
coordinates.flat_map do |coordinate|
|
||||
CARTO::SGMAP::QuartiersPrioritaires::Adapter.new(
|
||||
coordinate.map { |element| [element['lng'], element['lat']] }
|
||||
).to_params
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_cadastre(coordinates)
|
||||
|
|
|
@ -15,18 +15,16 @@ describe CARTO::SGMAP::QuartiersPrioritaires::Adapter do
|
|||
let(:status) { 200 }
|
||||
let(:body) { File.read('spec/support/files/geojson/response_qp.json') }
|
||||
|
||||
it { expect(subject).to be_a_instance_of(Hash) }
|
||||
it { expect(subject).to be_a_instance_of(Array) }
|
||||
|
||||
context 'Attributes' do
|
||||
let(:qp_code) { 'QP057019' }
|
||||
|
||||
subject { super()[qp_code] }
|
||||
it { expect(subject.first[:code]).to eq(qp_code) }
|
||||
it { expect(subject.first[:nom]).to eq('Hauts De Vallières') }
|
||||
it { expect(subject.first[:commune]).to eq('Metz') }
|
||||
|
||||
it { expect(subject[:code]).to eq(qp_code) }
|
||||
it { expect(subject[:nom]).to eq('Hauts De Vallières') }
|
||||
it { expect(subject[:commune]).to eq('Metz') }
|
||||
|
||||
it { expect(subject[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
|
||||
it { expect(subject.first[:geometry]).to eq({ :type => "MultiPolygon", :coordinates => [[[[6.2136923480551, 49.1342109827851], [6.21416055031881, 49.1338823553928]]]] }) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue