2 class WaysController < ApiController
5 before_action :authorize, :only => [:create, :update, :delete]
9 before_action :require_public_data, :only => [:create, :update, :delete]
10 before_action :check_api_writable, :only => [:create, :update, :delete]
11 before_action :check_api_readable, :except => [:create, :update, :delete]
12 around_action :api_call_handle_error, :api_call_timeout
17 way = Way.from_xml(request.raw_post, true)
19 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
20 way.create_with_history current_user
21 render :plain => way.id.to_s
25 way = Way.find(params[:id])
27 response.last_modified = way.timestamp
33 respond_to do |format|
42 way = Way.find(params[:id])
43 new_way = Way.from_xml(request.raw_post)
45 unless new_way && new_way.id == way.id
46 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
49 way.update_from(new_way, current_user)
50 render :plain => way.version.to_s
53 # This is the API call to delete a way
55 way = Way.find(params[:id])
56 new_way = Way.from_xml(request.raw_post)
58 if new_way && new_way.id == way.id
59 way.delete_with_history!(new_way, current_user)
60 render :plain => way.version.to_s
67 way = Way.includes(:nodes => :node_tags).find(params[:id])
71 # changeset_cache = {}
72 # user_display_name_cache = {}
76 way.nodes.uniq.each do |node|
79 visible_nodes[node.id] = node
86 respond_to do |format|
96 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
99 ids = params["ways"].split(",").collect(&:to_i)
101 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
103 @ways = Way.find(ids)
106 respond_to do |format|
112 # returns all the ways which are currently using the node given in the
113 # :id parameter. note that this used to return deleted ways as well, but
114 # this seemed not to be the expected behaviour, so it was removed.
116 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
118 @ways = Way.where(:id => wayids, :visible => true)
121 respond_to do |format|