Class: Api::V1::NoticesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/v1/notices_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/api/v1/notices_controller.rb', line 4

def index
  query = {}
  fields = %w{created_at message error_class}

  if params.key?(:start_date) && params.key?(:end_date)
    start_date = Time.parse(params[:start_date]).utc
    end_date = Time.parse(params[:end_date]).utc
    query = {:created_at => {"$lte" => end_date, "$gte" => start_date}}
  end

  results = benchmark("[api/v1/notices_controller] query time") do
    Notice.where(query).with(:consistency => :strong).only(fields).to_a
  end

  respond_to do |format|
    format.any(:html, :json) { render :json => JSON.dump(results) } # render JSON if no extension specified on path
    format.xml  { render :xml  => results }
  end
end