]> git.openstreetmap.org Git - rails.git/blob - app/controllers/way_controller.rb
various map API rails stuff
[rails.git] / app / controllers / way_controller.rb
1 class WayController < ApplicationController
2   require 'xml/libxml'
3
4   before_filter :authorize
5
6   def create
7     if request.put?
8       way = Way.from_xml(request.raw_post, true)
9
10       if way
11         way.user_id = @user.id
12         if way.save_with_history
13           render :text => way.id
14         else
15           render :nothing => true, :status => 500
16         end
17         return
18       else
19         render :nothing => true, :status => 400 # if we got here the doc didnt parse
20         return
21       end
22     end
23
24     render :nothing => true, :status => 500 # something went very wrong
25   end
26
27   def rest
28     unless Way.exists?(params[:id])
29       render :nothing => true, :status => 404
30       return
31     end
32
33     way = Way.find(params[:id])
34     case request.method
35    
36     when :get
37       unless way.visible
38         render :nothing => true, :status => 410
39         return
40       end
41       render :text => way.to_xml.to_s
42
43     when :delete
44       unless way.visible
45         render :nothing => true, :status => 410
46         return
47       end
48
49       way.visible = false
50       way.save_with_history
51       render :nothing => true
52       return
53     when :put
54       way = Way.from_xml(request.raw_post, true)
55
56       if way
57         way_in_db = Way.find(way.id)
58         if way_in_db
59           way_in_db.user_id = @user.id
60           way_in_db.tags = way.tags
61           way_in_db.segs = way.segs
62           way_in_db.timestamp = way.timestamp
63           way_in_db.visible = true
64           if way_in_db.save_with_history
65             render :text => way.id
66           else
67             render :nothing => true, :status => 500
68           end
69           return
70         else
71           render :nothing => true, :status => 404 # way doesn't exist yet
72         end
73       else
74         render :nothing => true, :status => 400 # if we got here the doc didnt parse
75         return
76       end
77     end
78   end
79 end