First draft of SensorReadingsController (needs tests)
parent
119689d8ef
commit
2ea0eae81e
|
@ -9,7 +9,7 @@ module Api
|
|||
SECRET = ENV.fetch("GCS_ID") { "" }
|
||||
|
||||
def create
|
||||
mutate Images::Create.run({device: current_device}, raw_json)
|
||||
mutate Images::Create.run(raw_json, device: current_device)
|
||||
end
|
||||
|
||||
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
|
|
@ -1,15 +1,16 @@
|
|||
FarmBot::Application.routes.draw do
|
||||
|
||||
namespace :api, defaults: {format: :json}, constraints: { format: "json" } do
|
||||
resources :images, only: [:create, :destroy, :show, :index]
|
||||
resources :regimens, only: [:create, :destroy, :index, :update]
|
||||
resources :peripherals, only: [:create, :destroy, :index, :update]
|
||||
resources :corpuses, only: [:index, :show]
|
||||
resources :logs, only: [:index, :create, :destroy]
|
||||
resources :sequences, only: [:create, :update, :destroy, :index, :show]
|
||||
resources :farm_events, only: [:create, :update, :destroy, :index]
|
||||
resources :tools, only: [:create, :show, :index, :destroy, :update]
|
||||
resources :points, only: [:create, :show, :index, :destroy, :update] do
|
||||
resources :images, only: [:create, :destroy, :show, :index]
|
||||
resources :sensor_readings, only: [:create, :destroy, :show, :index]
|
||||
resources :regimens, only: [:create, :destroy, :index, :update]
|
||||
resources :peripherals, only: [:create, :destroy, :index, :update]
|
||||
resources :corpuses, only: [:index, :show]
|
||||
resources :logs, only: [:index, :create, :destroy]
|
||||
resources :sequences, only: [:create, :update, :destroy, :index, :show]
|
||||
resources :farm_events, only: [:create, :update, :destroy, :index]
|
||||
resources :tools, only: [:create, :show, :index, :destroy, :update]
|
||||
resources :points, only: [:create, :show, :index, :destroy, :update] do
|
||||
post :search, on: :collection
|
||||
end
|
||||
resource :public_key, only: [:show]
|
||||
|
|
Loading…
Reference in New Issue