1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_availability, :only => [:create, :update, :delete]
7 after_filter :compress_output
11 way = Way.from_xml(request.raw_post, true)
14 if !way.preconditions_ok?
15 render :nothing => true, :status => :precondition_failed
17 way.user_id = @user.id
18 way.save_with_history!
20 render :text => way.id.to_s, :content_type => "text/plain"
23 render :nothing => true, :status => :bad_request
26 render :nothing => true, :status => :method_not_allowed
32 way = Way.find(params[:id])
35 render :text => way.to_xml.to_s, :content_type => "text/xml"
37 render :nothing => true, :status => :gone
39 rescue ActiveRecord::RecordNotFound
40 render :nothing => true, :status => :not_found
46 way = Way.find(params[:id])
49 new_way = Way.from_xml(request.raw_post)
51 if new_way and new_way.id == way.id
52 if !new_way.preconditions_ok?
53 render :nothing => true, :status => :precondition_failed
55 way.user_id = @user.id
56 way.tags = new_way.tags
59 way.save_with_history!
61 render :nothing => true
64 render :nothing => true, :status => :bad_request
67 render :nothing => true, :status => :gone
69 rescue ActiveRecord::RecordNotFound
70 render :nothing => true, :status => :not_found
76 way = Way.find(params[:id])
79 if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='way' and member_id=?", params[:id]])
80 render :nothing => true, :status => :precondition_failed
82 way.user_id = @user.id
86 way.save_with_history!
88 render :nothing => true
91 render :nothing => true, :status => :gone
93 rescue ActiveRecord::RecordNotFound
94 render :nothing => true, :status => :not_found
102 way = Way.find(params[:id])
105 nd_ids = way.nds + [-1]
106 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
109 doc = OSM::API.new.get_xml_doc
111 doc.root << node.to_xml_node()
113 doc.root << way.to_xml_node()
115 render :text => doc.to_s, :content_type => "text/xml"
117 render :nothing => true, :status => :gone
119 rescue ActiveRecord::RecordNotFound
120 render :nothing => true, :status => :not_found
126 ids = params['ways'].split(',').collect { |w| w.to_i }
132 doc = OSM::API.new.get_xml_doc
134 Way.find(ids).each do |way|
135 doc.root << way.to_xml_node
138 render :text => doc.to_s, :content_type => "text/xml"
140 render :nothing => true, :status => :bad_request
145 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
148 doc = OSM::API.new.get_xml_doc
150 Way.find(wayids).each do |way|
151 doc.root << way.to_xml_node
154 render :text => doc.to_s, :content_type => "text/xml"
156 render :nothing => true, :status => :bad_request