Class: ForestLiana::StatsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/forest_liana/stats_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user_from_jwt, #forest_user, papertrail?, #route_not_found, #serialize_model, #serialize_models

Instance Method Details

#showObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/forest_liana/stats_controller.rb', line 9

def show
  case params[:type].try(:downcase)
  when 'value'
    stat = ValueStatGetter.new(@resource, params)
  when 'pie'
    stat = PieStatGetter.new(@resource, params)
  when 'line'
    stat = LineStatGetter.new(@resource, params)
  end

  stat.perform
  if stat.record
    render json: serialize_model(stat.record), serializer: nil
  else
    render json: {status: 404}, status: :not_found, serializer: nil
  end
end