1 class WayController < ApplicationController
\r
4 before_filter :authorize
5 after_filter :compress_output
9 way = Way.from_xml(request.raw_post, true)
12 way.user_id = @user.id
13 unless way.preconditions_ok? # are the segments (and their nodes) visible?
14 render :nothing => true, :status => 412
18 if way.save_with_history
19 render :text => way.id.to_s
22 render :nothing => true, :status => 500
27 render :nothing => true, :status => 400 # if we got here the doc didnt parse
32 render :nothing => true, :status => 500 # something went very wrong
36 unless Way.exists?(params[:id])
37 render :nothing => true, :status => 404
41 way = Way.find(params[:id])
44 render :nothing => true, :status => 410
48 # In future, we might want to do all the data fetch in one step
49 seg_ids = way.segs + [-1]
50 segments = Segment.find_by_sql "select * from current_segments where visible = 1 and id IN (#{seg_ids.join(',')})"
52 node_ids = segments.collect {|segment| segment.node_a }
53 node_ids += segments.collect {|segment| segment.node_b }
55 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{node_ids.join(',')})")
58 doc = OSM::API.new.get_xml_doc
60 doc.root << node.to_xml_node()
62 segments.each do |segment|
63 doc.root << segment.to_xml_node()
65 doc.root << way.to_xml_node()
67 render :text => doc.to_s
71 unless Way.exists?(params[:id])
72 render :nothing => true, :status => 404
76 way = Way.find(params[:id])
81 render :nothing => true, :status => 410
84 render :text => way.to_xml.to_s
88 render :nothing => true, :status => 410
94 render :nothing => true
97 way = Way.from_xml(request.raw_post)
100 way_in_db = Way.find(way.id)
102 way_in_db.user_id = @user.id
103 way_in_db.tags = way.tags
104 way_in_db.segs = way.segs
105 way_in_db.timestamp = way.timestamp
106 way_in_db.visible = true
107 if way_in_db.save_with_history
108 render :text => way.id
110 render :nothing => true, :status => 500
114 render :nothing => true, :status => 404 # way doesn't exist yet
117 render :nothing => true, :status => 400 # if we got here the doc didnt parse
124 response.headers["Content-Type"] = 'text/xml'
125 ids = params['ways'].split(',').collect {|w| w.to_i }
127 waylist = Way.find(ids)
128 doc = OSM::API.new.get_xml_doc
129 waylist.each do |way|
130 doc.root << way.to_xml_node
132 render :text => doc.to_s
134 render :nothing => true, :status => 400