]> git.openstreetmap.org Git - rails.git/blob - app/controllers/way_controller.rb
gpx rss and gpx cleanups
[rails.git] / app / controllers / way_controller.rb
1 class WayController < ApplicationController
2   require 'xml/libxml'
3
4   before_filter :authorize
5   after_filter :compress_output
6
7   def create
8     if request.put?
9       way = Way.from_xml(request.raw_post, true)
10
11       if way
12         way.user_id = @user.id
13         if way.save_with_history
14           render :text => way.id
15         else
16           render :nothing => true, :status => 500
17         end
18         return
19       else
20         render :nothing => true, :status => 400 # if we got here the doc didnt parse
21         return
22       end
23     end
24
25     render :nothing => true, :status => 500 # something went very wrong
26   end
27
28   def rest
29     unless Way.exists?(params[:id])
30       render :nothing => true, :status => 404
31       return
32     end
33
34     way = Way.find(params[:id])
35     case request.method
36    
37     when :get
38       unless way.visible
39         render :nothing => true, :status => 410
40         return
41       end
42       render :text => way.to_xml.to_s
43
44     when :delete
45       unless way.visible
46         render :nothing => true, :status => 410
47         return
48       end
49
50       way.visible = false
51       way.save_with_history
52       render :nothing => true
53       return
54     when :put
55       way = Way.from_xml(request.raw_post)
56
57       if way
58         way_in_db = Way.find(way.id)
59         if way_in_db
60           way_in_db.user_id = @user.id
61           way_in_db.tags = way.tags
62           way_in_db.segs = way.segs
63           way_in_db.timestamp = way.timestamp
64           way_in_db.visible = true
65           if way_in_db.save_with_history
66             render :text => way.id
67           else
68             render :nothing => true, :status => 500
69           end
70           return
71         else
72           render :nothing => true, :status => 404 # way doesn't exist yet
73         end
74       else
75         render :nothing => true, :status => 400 # if we got here the doc didnt parse
76         return
77       end
78     end
79   end
80
81   def ways
82     response.headers["Content-Type"] = 'application/xml'
83     ids = params['ways'].split(',').collect {|w| w.to_i }
84     if ids.length > 0
85       waylist = Way.find(ids)
86       doc = get_xml_doc
87       waylist.each do |way|
88         doc.root << way.to_xml_node
89       end 
90       render :text => doc.to_s
91     else
92       render :nothing => true, :status => 400
93     end
94   end
95
96 end