1 class WayController < ApplicationController
4 before_filter :authorize, :only => [:create, :update, :delete]
5 before_filter :check_availability, :only => [:create, :update, :delete]
6 after_filter :compress_output
10 way = Way.from_xml(request.raw_post, true)
13 if !way.preconditions_ok?
14 render :nothing => true, :status => :precondition_failed
16 way.user_id = @user.id
18 if way.save_with_history
19 render :text => way.id.to_s, :content_type => "text/plain"
21 render :nothing => true, :status => :internal_server_error
25 render :nothing => true, :status => :bad_request
28 render :nothing => true, :status => :method_not_allowed
34 way = Way.find(params[:id])
37 render :text => way.to_xml.to_s, :content_type => "text/xml"
39 render :nothing => true, :status => :gone
41 rescue ActiveRecord::RecordNotFound
42 render :nothing => true, :status => :not_found
44 render :nothing => true, :status => :internal_server_error
50 way = Way.find(params[:id])
53 new_way = Way.from_xml(request.raw_post)
55 if new_way and new_way.id == way.id
56 if !new_way.preconditions_ok?
57 render :nothing => true, :status => :precondition_failed
59 way.user_id = @user.id
60 way.tags = new_way.tags
61 way.segs = new_way.segs
64 if way.save_with_history
65 render :nothing => true
67 render :nothing => true, :status => :internal_server_error
71 render :nothing => true, :status => :bad_request
74 render :nothing => true, :status => :gone
76 rescue ActiveRecord::RecordNotFound
77 render :nothing => true, :status => :not_found
79 render :nothing => true, :status => :internal_server_error
85 way = Way.find(params[:id])
88 way.user_id = @user.id
93 if way.save_with_history
94 render :nothing => true
96 render :nothing => true, :status => :internal_server_error
99 render :nothing => true, :status => :gone
101 rescue ActiveRecord::RecordNotFound
102 render :nothing => true, :status => :not_found
104 render :nothing => true, :status => :internal_server_error
110 way = Way.find(params[:id])
113 # In future, we might want to do all the data fetch in one step
114 seg_ids = way.segs + [-1]
115 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
117 node_ids = segments.collect {|segment| segment.node_a }
118 node_ids += segments.collect {|segment| segment.node_b }
120 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
123 doc = OSM::API.new.get_xml_doc
125 doc.root << node.to_xml_node()
127 segments.each do |segment|
128 doc.root << segment.to_xml_node()
130 doc.root << way.to_xml_node()
132 render :text => doc.to_s, :content_type => "text/xml"
134 render :nothing => true, :status => :gone
136 rescue ActiveRecord::RecordNotFound
137 render :nothing => true, :status => :not_found
139 render :nothing => true, :status => :internal_server_error
144 ids = params['ways'].split(',').collect { |w| w.to_i }
147 doc = OSM::API.new.get_xml_doc
149 Way.find(ids).each do |way|
150 doc.root << way.to_xml_node
153 render :text => doc.to_s, :content_type => "text/xml"
155 render :nothing => true, :status => :bad_request
160 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
163 doc = OSM::API.new.get_xml_doc
165 Way.find(wayids).each do |way|
166 doc.root << way.to_xml_node
169 render :text => doc.to_s, :content_type => "text/xml"
171 render :nothing => true, :status => :bad_request