1 class WayController < ApplicationController
4 before_filter :authorize, :only => [:create, :update, :delete]
5 after_filter :compress_output
9 way = Way.from_xml(request.raw_post, true)
12 if !way.preconditions_ok?
13 render :nothing => true, :status => :precondition_failed
15 way.user_id = @user.id
17 if way.save_with_history
18 render :text => way.id.to_s, :content_type => "text/plain"
20 render :nothing => true, :status => :internal_server_error
24 render :nothing => true, :status => :bad_request
27 render :nothing => true, :status => :method_not_allowed
33 way = Way.find(params[:id])
36 render :text => way.to_xml.to_s, :content_type => "text/xml"
38 render :nothing => true, :status => :gone
40 rescue ActiveRecord::RecordNotFound
41 render :nothing => true, :status => :not_found
43 render :nothing => true, :status => :internal_server_error
49 way = Way.find(params[:id])
52 new_way = Way.from_xml(request.raw_post)
54 if new_way and new_way.id == way.id
55 if !new_way.preconditions_ok?
56 render :nothing => true, :status => :precondition_failed
58 way.user_id = @user.id
59 way.tags = new_way.tags
60 way.segs = new_way.segs
63 if way.save_with_history
64 render :nothing => true
66 render :nothing => true, :status => :internal_server_error
70 render :nothing => true, :status => :bad_request
73 render :nothing => true, :status => :gone
75 rescue ActiveRecord::RecordNotFound
76 render :nothing => true, :status => :not_found
78 render :nothing => true, :status => :internal_server_error
84 way = Way.find(params[:id])
87 way.user_id = @user.id
92 if way.save_with_history
93 render :nothing => true
95 render :nothing => true, :status => :internal_server_error
98 render :nothing => true, :status => :gone
100 rescue ActiveRecord::RecordNotFound
101 render :nothing => true, :status => :not_found
103 render :nothing => true, :status => :internal_server_error
109 way = Way.find(params[:id])
112 # In future, we might want to do all the data fetch in one step
113 seg_ids = way.segs + [-1]
114 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
116 node_ids = segments.collect {|segment| segment.node_a }
117 node_ids += segments.collect {|segment| segment.node_b }
119 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
122 doc = OSM::API.new.get_xml_doc
124 doc.root << node.to_xml_node()
126 segments.each do |segment|
127 doc.root << segment.to_xml_node()
129 doc.root << way.to_xml_node()
131 render :text => doc.to_s, :content_type => "text/xml"
133 render :nothing => true, :status => :gone
135 rescue ActiveRecord::RecordNotFound
136 render :nothing => true, :status => :not_found
138 render :nothing => true, :status => :internal_server_error
143 ids = params['ways'].split(',').collect { |w| w.to_i }
146 doc = OSM::API.new.get_xml_doc
148 Way.find(ids).each do |way|
149 doc.root << way.to_xml_node
152 render :text => doc.to_s, :content_type => "text/xml"
154 render :nothing => true, :status => :bad_request
159 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
162 doc = OSM::API.new.get_xml_doc
164 Way.find(wayids).each do |way|
165 doc.root << way.to_xml_node
168 render :text => doc.to_s, :content_type => "text/xml"
170 render :nothing => true, :status => :bad_request