Add decription to geo_area
This commit is contained in:
parent
72d1ca1f42
commit
d099314e56
3 changed files with 44 additions and 14 deletions
|
@ -19,7 +19,7 @@ class Champs::CarteController < ApplicationController
|
||||||
def create
|
def create
|
||||||
champ = policy_scope(Champ).find(params[:champ_id])
|
champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
geo_area = champ.geo_areas.selections_utilisateur.new
|
geo_area = champ.geo_areas.selections_utilisateur.new
|
||||||
save_geometry!(geo_area, params_feature)
|
save_feature!(geo_area, params_feature)
|
||||||
|
|
||||||
render json: { feature: geo_area.to_feature }, status: :created
|
render json: { feature: geo_area.to_feature }, status: :created
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ class Champs::CarteController < ApplicationController
|
||||||
def update
|
def update
|
||||||
champ = policy_scope(Champ).find(params[:champ_id])
|
champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
geo_area = champ.geo_areas.selections_utilisateur.find(params[:id])
|
geo_area = champ.geo_areas.selections_utilisateur.find(params[:id])
|
||||||
save_geometry!(geo_area, params_feature)
|
save_feature!(geo_area, params_feature)
|
||||||
|
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
@ -43,7 +43,7 @@ class Champs::CarteController < ApplicationController
|
||||||
champ = policy_scope(Champ).find(params[:champ_id])
|
champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
params_features.each do |feature|
|
params_features.each do |feature|
|
||||||
geo_area = champ.geo_areas.selections_utilisateur.new
|
geo_area = champ.geo_areas.selections_utilisateur.new
|
||||||
save_geometry!(geo_area, feature)
|
save_feature!(geo_area, feature)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: champ.to_feature_collection, status: :created
|
render json: champ.to_feature_collection, status: :created
|
||||||
|
@ -59,8 +59,13 @@ class Champs::CarteController < ApplicationController
|
||||||
params[:features]
|
params[:features]
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_geometry!(geo_area, feature)
|
def save_feature!(geo_area, feature)
|
||||||
geo_area.geometry = feature[:geometry]
|
if feature[:geometry]
|
||||||
|
geo_area.geometry = feature[:geometry]
|
||||||
|
end
|
||||||
|
if feature[:properties] && feature[:properties][:description]
|
||||||
|
geo_area.description = feature[:properties][:description]
|
||||||
|
end
|
||||||
geo_area.save!
|
geo_area.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ class GeoArea < ApplicationRecord
|
||||||
belongs_to :champ
|
belongs_to :champ
|
||||||
|
|
||||||
store :properties, accessors: [
|
store :properties, accessors: [
|
||||||
|
:description,
|
||||||
:surface_intersection,
|
:surface_intersection,
|
||||||
:surface_parcelle,
|
:surface_parcelle,
|
||||||
:numero,
|
:numero,
|
||||||
|
|
|
@ -44,19 +44,43 @@ describe Champs::CarteController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PATCH #update' do
|
describe 'PATCH #update' do
|
||||||
let(:params) do
|
|
||||||
{
|
|
||||||
champ_id: champ.id,
|
|
||||||
id: geo_area.id,
|
|
||||||
feature: feature
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
patch :update, params: params
|
patch :update, params: params
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(response.status).to eq 204 }
|
context 'update geometry' do
|
||||||
|
let(:params) do
|
||||||
|
{
|
||||||
|
champ_id: champ.id,
|
||||||
|
id: geo_area.id,
|
||||||
|
feature: feature
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response.status).to eq 204 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'update description' do
|
||||||
|
let(:feature) do
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
description: 'un point'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
let(:params) do
|
||||||
|
{
|
||||||
|
champ_id: champ.id,
|
||||||
|
id: geo_area.id,
|
||||||
|
feature: feature
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it {
|
||||||
|
expect(response.status).to eq 204
|
||||||
|
expect(geo_area.reload.description).to eq('un point')
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue