From d5a43f1aa76c1e0086f08bec9c575d2a41ae9a9b Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Wed, 4 Jul 2012 13:45:29 +0100 Subject: Atom feed of request events We need not only new requests, but new outgoing correspondence of any sort. The idea is that this feed will contain any event that would have triggered an email to be sent to the public body, so can be used as an alternative, equivalent way to stay up-to-date with happenings on WDTK (or the Alaveteli installation of choice). --- app/controllers/api_controller.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'app/controllers/api_controller.rb') diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index a8c9b5fef..3001ca3cb 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -155,17 +155,27 @@ class ApiController < ApplicationController head :no_content end - def body_new_requests + def body_request_events feed_type = params[:feed_type] raise PermissionDenied.new("#{@public_body.id} != #{params[:id]}") if @public_body.id != params[:id].to_i - @requests = @public_body.info_requests + @events = InfoRequestEvent.find_by_sql([ + %(select info_request_events.* + from info_requests + join info_request_events on info_requests.id = info_request_events.info_request_id + where info_requests.public_body_id = ? + and info_request_events.event_type in ( + 'sent', 'followup_sent', 'resent', 'followup_resent' + ) + order by info_request_events.created_at desc + ), @public_body.id + ]) if feed_type == "atom" - render :template => "api/new_requests.atom", :layout => false + render :template => "api/request_events.atom", :layout => false elsif feed_type == "json" - render :json => @requests + render :json => @events else - raise ActiveRecord::RecordNotFound.new("Unrecognised feed type: " + feed_type) + raise ActiveRecord::RecordNotFound.new("Unrecognised feed type: #{feed_type}") end end -- cgit v1.2.3