1 class WayController < ApplicationController
4 before_filter :authorize
5 after_filter :compress_output
8 response.headers["Content-Type"] = 'text/xml'
10 way = Way.from_xml(request.raw_post, true)
13 way.user_id = @user.id
14 unless way.preconditions_ok? # are the segments (and their nodes) visible?
15 render :nothing => true, :status => 412
19 if way.save_with_history
20 render :text => way.id.to_s
23 render :nothing => true, :status => 500
28 render :nothing => true, :status => 400 # if we got here the doc didnt parse
33 render :nothing => true, :status => 500 # something went very wrong
37 unless Way.exists?(params[:id])
38 render :nothing => true, :status => 404
42 way = Way.find(params[:id])
45 render :nothing => true, :status => 410
49 # In future, we might want to do all the data fetch in one step
50 seg_ids = way.segs + [-1]
51 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
53 node_ids = segments.collect {|segment| segment.node_a }
54 node_ids += segments.collect {|segment| segment.node_b }
56 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
59 doc = OSM::API.new.get_xml_doc
61 doc.root << node.to_xml_node()
63 segments.each do |segment|
64 doc.root << segment.to_xml_node()
66 doc.root << way.to_xml_node()
68 render :text => doc.to_s
72 response.headers["Content-Type"] = 'text/xml'
73 unless Way.exists?(params[:id])
74 render :nothing => true, :status => 404
78 way = Way.find(params[:id])
84 render :nothing => true, :status => 410
87 render :text => way.to_xml.to_s
91 render :nothing => true, :status => 410
97 render :nothing => true
100 way = Way.from_xml(request.raw_post)
103 way_in_db = Way.find(way.id)
105 way_in_db.user_id = @user.id
106 way_in_db.tags = way.tags
107 way_in_db.segs = way.segs
108 way_in_db.timestamp = way.timestamp
109 way_in_db.visible = true
110 if way_in_db.save_with_history
111 render :text => way.id
113 render :nothing => true, :status => 500
117 render :nothing => true, :status => 404 # way doesn't exist yet
120 render :nothing => true, :status => 400 # if we got here the doc didnt parse
127 response.headers["Content-Type"] = 'text/xml'
128 ids = params['ways'].split(',').collect {|w| w.to_i }
130 waylist = Way.find(ids)
131 doc = OSM::API.new.get_xml_doc
132 waylist.each do |way|
133 doc.root << way.to_xml_node
135 render :text => doc.to_s
137 render :nothing => true, :status => 400