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
19 if way.save_with_history
20 render :text => way.id.to_s, :content_type => "text/plain"
22 render :nothing => true, :status => :internal_server_error
26 render :nothing => true, :status => :bad_request
29 render :nothing => true, :status => :method_not_allowed
35 way = Way.find(params[:id])
38 render :text => way.to_xml.to_s, :content_type => "text/xml"
40 render :nothing => true, :status => :gone
42 rescue ActiveRecord::RecordNotFound
43 render :nothing => true, :status => :not_found
45 render :nothing => true, :status => :internal_server_error
51 way = Way.find(params[:id])
54 new_way = Way.from_xml(request.raw_post)
56 if new_way and new_way.id == way.id
57 if !new_way.preconditions_ok?
58 render :nothing => true, :status => :precondition_failed
60 way.user_id = @user.id
61 way.tags = new_way.tags
62 way.segs = new_way.segs
65 if way.save_with_history
66 render :nothing => true
68 render :nothing => true, :status => :internal_server_error
72 render :nothing => true, :status => :bad_request
75 render :nothing => true, :status => :gone
77 rescue ActiveRecord::RecordNotFound
78 render :nothing => true, :status => :not_found
80 render :nothing => true, :status => :internal_server_error
86 way = Way.find(params[:id])
89 way.user_id = @user.id
94 if way.save_with_history
95 render :nothing => true
97 render :nothing => true, :status => :internal_server_error
100 render :nothing => true, :status => :gone
102 rescue ActiveRecord::RecordNotFound
103 render :nothing => true, :status => :not_found
105 render :nothing => true, :status => :internal_server_error
111 way = Way.find(params[:id])
114 # In future, we might want to do all the data fetch in one step
115 seg_ids = way.segs + [-1]
116 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
118 node_ids = segments.collect {|segment| segment.node_a }
119 node_ids += segments.collect {|segment| segment.node_b }
121 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
124 doc = OSM::API.new.get_xml_doc
126 doc.root << node.to_xml_node()
128 segments.each do |segment|
129 doc.root << segment.to_xml_node()
131 doc.root << way.to_xml_node()
133 render :text => doc.to_s, :content_type => "text/xml"
135 render :nothing => true, :status => :gone
137 rescue ActiveRecord::RecordNotFound
138 render :nothing => true, :status => :not_found
140 render :nothing => true, :status => :internal_server_error
146 ids = params['ways'].split(',').collect { |w| w.to_i }
152 doc = OSM::API.new.get_xml_doc
154 Way.find(ids).each do |way|
155 doc.root << way.to_xml_node
158 render :text => doc.to_s, :content_type => "text/xml"
160 render :nothing => true, :status => :bad_request
165 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
168 doc = OSM::API.new.get_xml_doc
170 Way.find(wayids).each do |way|
171 doc.root << way.to_xml_node
174 render :text => doc.to_s, :content_type => "text/xml"
176 render :nothing => true, :status => :bad_request