First draft of SensorReadingsController (needs tests)
parent
119689d8ef
commit
2ea0eae81e
|
@ -9,7 +9,7 @@ module Api
|
||||||
SECRET = ENV.fetch("GCS_ID") { "" }
|
SECRET = ENV.fetch("GCS_ID") { "" }
|
||||||
|
|
||||||
def create
|
def create
|
||||||
mutate Images::Create.run({device: current_device}, raw_json)
|
mutate Images::Create.run(raw_json, device: current_device)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
module Api
|
||||||
|
class SensorReadingsController < Api::AbstractController
|
||||||
|
def create
|
||||||
|
mutate SensorReadings::Create.run(raw_json, device: current_device)
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
render json: readings
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
render json: reading
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
reading.destroy!
|
||||||
|
render json: ""
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def readings
|
||||||
|
SensorReading.where(device: current_device)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reading
|
||||||
|
@image ||= readings.find(params[:id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
module SensorReadings
|
||||||
|
class Create < Mutations::Command
|
||||||
|
required do
|
||||||
|
model :device, class: Device
|
||||||
|
float :x
|
||||||
|
float :y
|
||||||
|
float :z
|
||||||
|
integer :value
|
||||||
|
integer :pin
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
SensorReading.create!(inputs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,6 +2,7 @@ FarmBot::Application.routes.draw do
|
||||||
|
|
||||||
namespace :api, defaults: {format: :json}, constraints: { format: "json" } do
|
namespace :api, defaults: {format: :json}, constraints: { format: "json" } do
|
||||||
resources :images, only: [:create, :destroy, :show, :index]
|
resources :images, only: [:create, :destroy, :show, :index]
|
||||||
|
resources :sensor_readings, only: [:create, :destroy, :show, :index]
|
||||||
resources :regimens, only: [:create, :destroy, :index, :update]
|
resources :regimens, only: [:create, :destroy, :index, :update]
|
||||||
resources :peripherals, only: [:create, :destroy, :index, :update]
|
resources :peripherals, only: [:create, :destroy, :index, :update]
|
||||||
resources :corpuses, only: [:index, :show]
|
resources :corpuses, only: [:index, :show]
|
||||||
|
|
Loading…
Reference in New Issue