problems_controller.rb
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Api::V1::ProblemsController < ApplicationController
respond_to :json, :xml
FIELDS = %w{_id app_id app_name environment message where first_notice_at last_notice_at resolved resolved_at notices_count}
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
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
end