X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a6f61bd18aebe24d7488447b18d49158b15a71fa..e62fe92282de957f0be76bee2d21de50bffd8625:/app/controllers/segment_controller.rb diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 21de13be8..966ede72a 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -1,5 +1,4 @@ class SegmentController < ApplicationController - require 'xml/libxml' before_filter :authorize @@ -9,9 +8,17 @@ class SegmentController < ApplicationController segment = Segment.from_xml(request.raw_post, true) if segment + segment.user_id = @user.id - if segment.save_with_history + a = Node.find(segment.node_a.to_i) + b = Node.find(segment.node_b.to_i) + + unless a and a.visible and b and b.visible + render :nothing => true, :status => 400 + end + + if segment.save_with_history render :text => segment.id else render :nothing => true, :status => 500 @@ -29,7 +36,7 @@ class SegmentController < ApplicationController def rest unless Segment.exists?(params[:id]) - render :nothing => true, :status => 400 + render :nothing => true, :status => 404 return end @@ -56,9 +63,10 @@ class SegmentController < ApplicationController segment.timestamp = Time.now segment.user_id = @user.id - segment.latitude = new_segment.latitude - segment.longitude = new_segment.longitude + segment.node_a = new_segment.node_a + segment.node_b = new_segment.node_b segment.tags = new_segment.tags + segment.visible = new_segment.visible if segment.id == new_segment.id and segment.save_with_history render :nothing => true, :status => 200 @@ -70,5 +78,34 @@ class SegmentController < ApplicationController end + def history + segment = Segment.find(params[:id]) + + unless segment + render :nothing => true, :staus => 404 + return + end + + doc = XML::Document.new + doc.encoding = 'UTF-8' + root = XML::Node.new 'osm' + root['version'] = '0.4' + root['generator'] = 'OpenStreetMap server' + doc.root = root + + segment.old_segments.each do |old_segment| + el1 = XML::Node.new 'segment' + el1['id'] = old_segment.id.to_s + el1['from'] = old_segment.node_a.to_s + el1['to'] = old_segment.node_b.to_s + Segment.split_tags(el1, old_segment.tags) + el1['visible'] = old_segment.visible.to_s + el1['timestamp'] = old_segment.timestamp.xmlschema + root << el1 + end + + render :text => doc.to_s + end + end