Class: Iro::DatapointsController
- Inherits:
-
ApplicationController
- Object
- Wco::ApplicationController
- ApplicationController
- Iro::DatapointsController
- Defined in:
- app/controllers/iro/datapoints_controller.rb
Overview
require_dependency “iro/application_controller”
Instance Method Summary collapse
-
#create ⇒ Object
params: d, k, v.
- #index ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
params: d, k, v
7 8 9 10 11 12 13 14 |
# File 'app/controllers/iro/datapoints_controller.rb', line 7 def create begin Iro::Datapoint.create( k: params[:k], v: params[:v], created_at: params[:time] ) render json: { status: :ok } rescue ActiveRecord::NotNullViolation => exception render json: { status: :unauthorized }, status: :unauthorized end end |
#index ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/iro/datapoints_controller.rb', line 16 def index # from = '2023-12-20' # to = '2023-12-01' # points = Iro::Datapoint.where( k: params[:k] ).joins( :dates ) sql = "SELECT dps.k, dps.v, d.date FROM iro_datapoints as dps RIGHT JOIN dates d ON d.date = dps.d WHERE d.date BETWEEN '2023-12-01' AND '2023-12-31' ORDER BY d.date;" outs = ActiveRecord::Base.connection.execute(sql) puts! outs, 'outs' render json: outs end |