diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-05-24 14:05:17 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-06-06 19:34:57 +0100 |
commit | 132dc3e9862d85109eb4a0e5946c22d3ec97d4bb (patch) | |
tree | 452c7709f8f340ef86b914712b708f193dfa929a /app/controllers/api_controller.rb | |
parent | 257ba137aa1ba1b2357e3fdc8a83e2c6947cae3d (diff) |
Work in progress on getting new APIController test to pass. They don't, yet!
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r-- | app/controllers/api_controller.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 205ad1c3b..ed567640e 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -26,7 +26,27 @@ class ApiController < ApplicationController end def create_request - + json = ActiveSupport::JSON.decode(params[:request_json]) + existing_request = InfoRequest.find_by_existing_request(json["title"], + @public_body.id, + json["body"]) + info_request = InfoRequest.new(:title => json["title"], + :public_body_id => @public_body.id, + :described_state => "awaiting_response", + :external_user_name => json["external_user_name"], + :external_url => json["external_url"]) + outgoing_message = OutgoingMessage.new(json["body"]) + info_request.outgoing_messages << outgoing_messages + outgoing_message.info_request = info_request + # See if values were valid or not + if !existing_request.nil? || !info_request.valid? + # We don't want the error "Outgoing messages is invalid", as the outgoing message + # will be valid for a specific reason which we are displaying anyway. + info_request.errors.delete("outgoing_messages") + render :json => {'errors' => :info_request.errors.to_s} + else + render :json => {'url' => 'http://goo.com'} + end end def add_correspondence |