-
- case request.method
-
- when :get
- unless way.visible
- render :nothing => true, :status => 410
- return
- end
- render :text => way.to_xml.to_s
-
- when :delete
- if way.visible
- way.visible = false
- way.save_with_history
- render :nothing => true
- else
- render :nothing => true, :status => 410
- end
-
- when :put
- new_way = Way.from_xml(request.raw_post)
-
- if new_way
- unless new_way.preconditions_ok? # are the segments (and their nodes) visible?
- render :nothing => true, :status => HTTP_PRECONDITION_FAILED
- return
- end
-
- way.user_id = @user.id
- way.tags = new_way.tags
- way.segs = new_way.segs
- way.timestamp = new_way.timestamp
- way.visible = true
-
- if way.id == new_way.id and way.save_with_history
- render :nothing => true
- else
- render :nothing => true, :status => 500
- end
- else
- render :nothing => true, :status => 400 # if we got here the doc didnt parse
+
+ if way.visible
+ nd_ids = way.nds + [-1]
+ nodes = Node.find(:all, :conditions => ["visible = ? AND id IN (#{nd_ids.join(',')})", true])
+
+ # Render
+ doc = OSM::API.new.get_xml_doc
+ nodes.each do |node|
+ doc.root << node.to_xml_node()