Class: Api::V1::ProblemsController

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

Constant Summary collapse

FIELDS =
%w{_id app_id app_name environment message where first_notice_at last_notice_at resolved resolved_at notices_count}

Instance Method Summary collapse

Instance Method Details

#indexObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/api/v1/problems_controller.rb', line 21

def index
  query = {}

  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 = {:first_notice_at=>{"$lte"=>end_date}, "$or"=>[{:resolved_at=>nil}, {:resolved_at=>{"$gte"=>start_date}}]}
  end

  results = benchmark("[api/v1/problems_controller/index] query time") do
    Problem.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

#showObject


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

def show
  result = benchmark("[api/v1/problems_controller/show] query time") do
    begin
      Problem.only(FIELDS).find(params[:id])
    rescue Mongoid::Errors::DocumentNotFound
      head :not_found
      return false
    end
  end

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