1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_availability, :only => [:create, :update, :delete]
7 after_filter :compress_output
11 way = Way.from_xml(request.raw_post, true)
14 if !way.preconditions_ok?
15 render :nothing => true, :status => :precondition_failed
17 way.user_id = @user.id
18 way.save_with_history!
20 render :text => way.id.to_s, :content_type => "text/plain"
23 render :nothing => true, :status => :bad_request
26 render :nothing => true, :status => :method_not_allowed
32 way = Way.find(params[:id])
35 render :text => way.to_xml.to_s, :content_type => "text/xml"
37 render :nothing => true, :status => :gone
39 rescue ActiveRecord::RecordNotFound
40 render :nothing => true, :status => :not_found
46 way = Way.find(params[:id])
49 new_way = Way.from_xml(request.raw_post)
51 if new_way and new_way.id == way.id
52 if !new_way.preconditions_ok?
53 render :nothing => true, :status => :precondition_failed
55 way.user_id = @user.id
56 way.tags = new_way.tags
57 way.segs = new_way.segs
59 way.save_with_history!
61 render :nothing => true
64 render :nothing => true, :status => :bad_request
67 render :nothing => true, :status => :gone
69 rescue ActiveRecord::RecordNotFound
70 render :nothing => true, :status => :not_found
76 way = Way.find(params[:id])
79 way.user_id = @user.id
83 way.save_with_history!
85 render :nothing => true
87 render :nothing => true, :status => :gone
89 rescue ActiveRecord::RecordNotFound
90 render :nothing => true, :status => :not_found
96 way = Way.find(params[:id])
99 # In future, we might want to do all the data fetch in one step
100 seg_ids = way.segs + [-1]
101 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
103 node_ids = segments.collect {|segment| segment.node_a }
104 node_ids += segments.collect {|segment| segment.node_b }
106 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
109 doc = OSM::API.new.get_xml_doc
111 doc.root << node.to_xml_node()
113 segments.each do |segment|
114 doc.root << segment.to_xml_node()
116 doc.root << way.to_xml_node()
118 render :text => doc.to_s, :content_type => "text/xml"
120 render :nothing => true, :status => :gone
122 rescue ActiveRecord::RecordNotFound
123 render :nothing => true, :status => :not_found
129 ids = params['ways'].split(',').collect { |w| w.to_i }
135 doc = OSM::API.new.get_xml_doc
137 Way.find(ids).each do |way|
138 doc.root << way.to_xml_node
141 render :text => doc.to_s, :content_type => "text/xml"
143 render :nothing => true, :status => :bad_request
148 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
151 doc = OSM::API.new.get_xml_doc
153 Way.find(wayids).each do |way|
154 doc.root << way.to_xml_node
157 render :text => doc.to_s, :content_type => "text/xml"
159 render :nothing => true, :status => :bad_request