Save Cadastre
This commit is contained in:
parent
b5f2163c51
commit
6a3525c7e2
8 changed files with 129 additions and 18 deletions
|
@ -18,14 +18,27 @@ class Users::CarteController < UsersController
|
|||
dossier = current_user_dossier
|
||||
|
||||
dossier.quartier_prioritaires.map(&:destroy)
|
||||
dossier.cadastres.map(&:destroy)
|
||||
|
||||
unless params[:json_latlngs].blank?
|
||||
if dossier.procedure.module_api_carto.quartiers_prioritaires?
|
||||
qp_list = generate_qp JSON.parse(params[:json_latlngs])
|
||||
|
||||
qp_list.each do |key, qp|
|
||||
qp.merge!({dossier_id: dossier.id})
|
||||
qp[:geometry] = qp[:geometry].to_json
|
||||
QuartierPrioritaire.new(qp).save
|
||||
QuartierPrioritaire.create(qp)
|
||||
end
|
||||
end
|
||||
|
||||
if dossier.procedure.module_api_carto.cadastre?
|
||||
cadastre_list = generate_cadastre JSON.parse(params[:json_latlngs])
|
||||
|
||||
cadastre_list.each do |cadastre|
|
||||
cadastre.merge!({dossier_id: dossier.id})
|
||||
cadastre[:geometry] = cadastre[:geometry].to_json
|
||||
Cadastre.create(cadastre)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -82,7 +95,7 @@ class Users::CarteController < UsersController
|
|||
def generate_cadastre coordinates
|
||||
cadastre = []
|
||||
|
||||
coordinates.each_with_index do |coordinate, index |
|
||||
coordinates.each_with_index do |coordinate, index|
|
||||
coordinate = coordinates[index].map { |latlng| [latlng['lng'], latlng['lat']] }
|
||||
cadastre << CARTO::SGMAP::Cadastre::Adapter.new(coordinate).to_params
|
||||
end
|
||||
|
|
|
@ -13,6 +13,7 @@ class Dossier < ActiveRecord::Base
|
|||
has_many :pieces_justificatives, dependent: :destroy
|
||||
has_many :champs, dependent: :destroy
|
||||
has_many :quartier_prioritaires, dependent: :destroy
|
||||
has_many :cadastres, dependent: :destroy
|
||||
belongs_to :procedure
|
||||
belongs_to :user
|
||||
has_many :commentaires, dependent: :destroy
|
||||
|
|
|
@ -8,15 +8,25 @@ class CARTO::SGMAP::Cadastre::Adapter
|
|||
end
|
||||
|
||||
def to_params
|
||||
params = []
|
||||
|
||||
data_source[:features].each do |feature|
|
||||
tmp = feature[:properties]
|
||||
data_source[:features].inject([]) do |acc, feature|
|
||||
tmp = filter_properties feature[:properties]
|
||||
tmp[:geometry] = feature[:geometry]
|
||||
|
||||
params << tmp
|
||||
acc << tmp
|
||||
end
|
||||
end
|
||||
|
||||
params
|
||||
def filter_properties properties
|
||||
{
|
||||
surface_intersection: properties[:surface_intersection],
|
||||
surface_parcelle: properties[:surface_parcelle],
|
||||
numero: properties[:numero],
|
||||
feuille: properties[:feuille],
|
||||
section: properties[:section],
|
||||
code_dep: properties[:code_dep],
|
||||
nom_com: properties[:nom_com],
|
||||
code_com: properties[:code_com],
|
||||
code_arr: properties[:code_arr]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,8 @@ require 'spec_helper'
|
|||
RSpec.describe Users::CarteController, type: :controller do
|
||||
let(:bad_adresse) { 'babouba' }
|
||||
|
||||
let(:procedure) { create(:procedure, :with_api_carto) }
|
||||
let(:module_api_carto) { create(:module_api_carto, :with_api_carto) }
|
||||
let(:procedure) { create(:procedure, module_api_carto: module_api_carto) }
|
||||
let(:dossier) { create(:dossier, :with_user, procedure: procedure) }
|
||||
|
||||
let(:dossier_with_no_carto) { create(:dossier, :with_user, :with_procedure) }
|
||||
|
@ -86,6 +87,8 @@ RSpec.describe Users::CarteController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'Save quartier prioritaire' do
|
||||
let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter).
|
||||
to receive(:to_params).
|
||||
|
@ -117,10 +120,6 @@ RSpec.describe Users::CarteController, type: :controller do
|
|||
context 'when json_latlngs params is informed' do
|
||||
let(:json_latlngs) { '[[{"lat":48.87442541960633,"lng":2.3859214782714844},{"lat":48.87273183590832,"lng":2.3850631713867183},{"lat":48.87081237174292,"lng":2.3809432983398438},{"lat":48.8712640169951,"lng":2.377510070800781},{"lat":48.87510283703279,"lng":2.3778533935546875},{"lat":48.87544154230615,"lng":2.382831573486328},{"lat":48.87442541960633,"lng":2.3859214782714844}]]' }
|
||||
|
||||
before do
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.quartier_prioritaires.size).to eq(1) }
|
||||
|
||||
describe 'Quartier Prioritaire' do
|
||||
|
@ -133,6 +132,59 @@ RSpec.describe Users::CarteController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Save cadastre' do
|
||||
let(:module_api_carto) { create(:module_api_carto, :with_cadastre) }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(CARTO::SGMAP::Cadastre::Adapter).
|
||||
to receive(:to_params).
|
||||
and_return([{:surface_intersection=>"0.0006", :surface_parcelle=>11252.692583090324, :numero=>"0013", :feuille=>1, :section=>"CD", :code_dep=>"30", :nom_com=>"Le Grau-du-Roi", :code_com=>"133", :code_arr=>"000", :geometry=>{:type=>"MultiPolygon", :coordinates=>[[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]]}}])
|
||||
|
||||
post :save, dossier_id: dossier.id, json_latlngs: json_latlngs
|
||||
end
|
||||
|
||||
context 'when json_latlngs params is empty' do
|
||||
context 'when dossier have cadastres in database' do
|
||||
let!(:dossier) { create(:dossier, :with_user, :with_procedure, :with_two_cadastres) }
|
||||
|
||||
before do
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
context 'when value is empty' do
|
||||
let(:json_latlngs) { '' }
|
||||
it { expect(dossier.cadastres.size).to eq(0) }
|
||||
end
|
||||
|
||||
context 'when value is empty array' do
|
||||
let(:json_latlngs) { '[]' }
|
||||
it { expect(dossier.cadastres.size).to eq(0) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when json_latlngs params is informed' do
|
||||
let(:json_latlngs) { '[[{"lat":48.87442541960633,"lng":2.3859214782714844},{"lat":48.87273183590832,"lng":2.3850631713867183},{"lat":48.87081237174292,"lng":2.3809432983398438},{"lat":48.8712640169951,"lng":2.377510070800781},{"lat":48.87510283703279,"lng":2.3778533935546875},{"lat":48.87544154230615,"lng":2.382831573486328},{"lat":48.87442541960633,"lng":2.3859214782714844}]]' }
|
||||
|
||||
it { expect(dossier.cadastres.size).to eq(1) }
|
||||
|
||||
describe 'Cadastre' do
|
||||
subject { Cadastre.last }
|
||||
|
||||
it { expect(subject.surface_intersection).to eq('0.0006') }
|
||||
it { expect(subject.surface_parcelle).to eq(11252.6925830903) }
|
||||
it { expect(subject.numero).to eq('0013') }
|
||||
it { expect(subject.feuille).to eq(1) }
|
||||
it { expect(subject.section).to eq('CD') }
|
||||
it { expect(subject.code_dep).to eq('30') }
|
||||
it { expect(subject.nom_com).to eq('Le Grau-du-Roi') }
|
||||
it { expect(subject.code_com).to eq('133') }
|
||||
it { expect(subject.code_arr).to eq('000') }
|
||||
it { expect(subject.geometry).to eq({"type"=>"MultiPolygon", "coordinates"=>[[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]]}) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get_position' do
|
||||
|
|
7
spec/factories/cadastre.rb
Normal file
7
spec/factories/cadastre.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
FactoryGirl.define do
|
||||
factory :cadastre do
|
||||
numero '001'
|
||||
feuille 1
|
||||
section 'OM'
|
||||
end
|
||||
end
|
|
@ -35,5 +35,16 @@ FactoryGirl.define do
|
|||
dossier.quartier_prioritaires << qp2
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_two_cadastres do
|
||||
after(:build) do |dossier, _evaluator|
|
||||
|
||||
qp1 = create(:cadastre)
|
||||
qp2 = create(:cadastre)
|
||||
|
||||
dossier.cadastres << qp1
|
||||
dossier.cadastres << qp2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,22 @@ describe CARTO::SGMAP::Cadastre::Adapter do
|
|||
it { expect(subject).to be_a_instance_of(Array) }
|
||||
it { expect(subject.size).to eq 16 }
|
||||
|
||||
describe 'Attribut filter' do
|
||||
let(:adapter) { described_class.new(coordinates) }
|
||||
subject { adapter.filter_properties adapter.data_source }
|
||||
|
||||
it { expect(subject.size).to eq 9 }
|
||||
it { expect(subject.keys).to eq [:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr] }
|
||||
end
|
||||
|
||||
describe 'Attributes' do
|
||||
subject { super().first }
|
||||
|
||||
|
@ -31,7 +47,7 @@ describe CARTO::SGMAP::Cadastre::Adapter do
|
|||
it { expect(subject[:code_com]).to eq('046') }
|
||||
it { expect(subject[:code_arr]).to eq('000') }
|
||||
|
||||
it { expect(subject[:geometry]).to eq({type: "MultiPolygon", coordinates: [[[[2.4362443, 48.8092078], [2.436384, 48.8092043], [2.4363802, 48.8091414]]]] })}
|
||||
it { expect(subject[:geometry]).to eq({type: "MultiPolygon", coordinates: [[[[2.4362443, 48.8092078], [2.436384, 48.8092043], [2.4363802, 48.8091414]]]]}) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ describe Dossier do
|
|||
it { is_expected.to have_many(:champs) }
|
||||
it { is_expected.to have_many(:commentaires) }
|
||||
it { is_expected.to have_many(:quartier_prioritaires) }
|
||||
it { is_expected.to have_many(:cadastres) }
|
||||
it { is_expected.to have_one(:cerfa) }
|
||||
it { is_expected.to have_one(:etablissement) }
|
||||
it { is_expected.to have_one(:entreprise) }
|
||||
|
|
Loading…
Reference in a new issue