1 class WayController < ApplicationController
4 before_filter :authorize, :only => [:create, :update, :destroy]
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
61 way.timestamp = new_way.timestamp
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
91 if way.save_with_history
92 render :nothing => true
94 render :nothing => true, :status => :internal_server_error
97 render :nothing => true, :status => :gone
99 rescue ActiveRecord::RecordNotFound
100 render :nothing => true, :status => :not_found
102 render :nothing => true, :status => :internal_server_error
108 way = Way.find(params[:id])
111 # In future, we might want to do all the data fetch in one step
112 seg_ids = way.segs + [-1]
113 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
115 node_ids = segments.collect {|segment| segment.node_a }
116 node_ids += segments.collect {|segment| segment.node_b }
118 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
121 doc = OSM::API.new.get_xml_doc
123 doc.root << node.to_xml_node()
125 segments.each do |segment|
126 doc.root << segment.to_xml_node()
128 doc.root << way.to_xml_node()
130 render :text => doc.to_s, :content_type => "text/xml"
132 render :nothing => true, :status => :gone
134 rescue ActiveRecord::RecordNotFound
135 render :nothing => true, :status => :not_found
137 render :nothing => true, :status => :internal_server_error
142 ids = params['ways'].split(',').collect { |w| w.to_i }
145 doc = OSM::API.new.get_xml_doc
147 Way.find(ids).each do |way|
148 doc.root << way.to_xml_node
151 render :text => doc.to_s, :content_type => "text/xml"
153 render :nothing => true, :status => :bad_request
158 wayids = WaySegment.find(:all, :conditions => ['segment_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
161 doc = OSM::API.new.get_xml_doc
163 Way.find(wayids).each do |way|
164 doc.root << way.to_xml_node
167 render :text => doc.to_s, :content_type => "text/xml"
169 render :nothing => true, :status => :bad_request