1 class SegmentController < ApplicationController
4 before_filter :authorize
7 response.headers["Content-Type"] = 'application/xml'
9 segment = Segment.from_xml(request.raw_post, true)
13 segment.user_id = @user.id
15 a = Node.find(segment.node_a.to_i)
16 b = Node.find(segment.node_b.to_i)
18 unless a and a.visible and b and b.visible
19 render :nothing => true, :status => 400
22 if segment.save_with_history
23 render :text => segment.id
25 render :nothing => true, :status => 500
30 render :nothing => true, :status => 400 # if we got here the doc didnt parse
35 render :nothing => true, :status => 500 # something went very wrong
39 response.headers["Content-Type"] = 'application/xml'
40 unless Segment.exists?(params[:id])
41 render :nothing => true, :status => 404
45 segment = Segment.find(params[:id])
50 render :text => segment.to_xml.to_s
56 segment.save_with_history
57 render :nothing => true
59 render :nothing => true, :status => 410
63 new_segment = Segment.from_xml(request.raw_post)
65 segment.timestamp = Time.now
66 segment.user_id = @user.id
68 segment.node_a = new_segment.node_a
69 segment.node_b = new_segment.node_b
70 segment.tags = new_segment.tags
71 segment.visible = new_segment.visible
73 if segment.id == new_segment.id and segment.save_with_history
74 render :nothing => true, :status => 200
76 render :nothing => true, :status => 500