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, #serialize_model, #serialize_models

Instance Method Details

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/forest_liana/stats_controller.rb', line 5

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

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