Class: Iro::DatapointsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/iro/datapoints_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #schwab_sync

Instance Method Details

#createObject

params: d, k, v



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/iro/datapoints_controller.rb', line 5

def create
  authorize! :create, Iro::Datapoint
  begin
    Iro::Datapoint.create!(
      date:  params[:d],
      kind:  params[:k],
      value: params[:v],
    )
    render json: { status: :ok }
  rescue Mongoid::Errors::Validations => e
    render json: { status: 401 }, status: 401
  end
end

#indexObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/iro/datapoints_controller.rb', line 19

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