X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/a6f61bd18aebe24d7488447b18d49158b15a71fa..fac305e87b9a2df59064ddad666304ceb3d7f7a7:/app/controllers/segment_controller.rb?ds=sidebyside diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 21de13be8..7e77609f3 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -1,17 +1,26 @@ class SegmentController < ApplicationController - require 'xml/libxml' before_filter :authorize + after_filter :compress_output def create + response.headers["Content-Type"] = 'application/xml' if request.put? 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 @@ -28,8 +37,9 @@ class SegmentController < ApplicationController end def rest + response.headers["Content-Type"] = 'application/xml' unless Segment.exists?(params[:id]) - render :nothing => true, :status => 400 + render :nothing => true, :status => 404 return end @@ -56,9 +66,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 +81,19 @@ class SegmentController < ApplicationController end + def segments + response.headers["Content-Type"] = 'application/xml' + ids = params['segments'].split(',').collect {|s| s.to_i } + if ids.length > 0 + segmentlist = Segment.find(ids) + doc = get_xml_doc + segmentlist.each do |segment| + doc.root << segment.to_xml_node + end + render :text => doc.to_s + else + render :nothing => true, :status => 400 + end + end end