[UNSTABLE] Begin `sensor` resource implementation.

pull/666/head
Rick Carlino 2018-02-17 11:43:46 -06:00
parent afbb00da63
commit bd2919e29a
9 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,24 @@
module Api
class SensorsController < Api::AbstractController
def index
raise "Not yet implements :("
end
def show
raise "Not yet implements :("
end
def create
raise "Not yet implements :("
end
def update
raise "Not yet implements :("
end
def destroy
raise "Not yet implements :("
end
end
end

View File

@ -0,0 +1,3 @@
class Sensor < ApplicationRecord
belongs_to :device
end

View File

@ -0,0 +1,3 @@
class SensorSerializer < ActiveModel::Serializer
attributes :id, :pin, :label, :mode
end

View File

@ -1,5 +1,6 @@
FarmBot::Application.routes.draw do
resources :sensors
namespace :api, defaults: {format: :json}, constraints: { format: "json" } do
resources :images, only: [:create, :destroy, :show, :index]
resources :sensor_readings, only: [:create, :destroy, :show, :index]

View File

@ -0,0 +1,12 @@
class CreateSensors < ActiveRecord::Migration[5.1]
def change
create_table :sensors do |t|
t.references :device, foreign_key: true
t.integer :pin
t.string :label
t.integer :mode
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180215224528) do
ActiveRecord::Schema.define(version: 20180217173606) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -294,9 +294,20 @@ ActiveRecord::Schema.define(version: 20180215224528) do
t.integer "pin"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "mode", default: 0
t.index ["device_id"], name: "index_sensor_readings_on_device_id"
end
create_table "sensors", force: :cascade do |t|
t.bigint "device_id"
t.integer "pin"
t.string "label"
t.integer "mode"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["device_id"], name: "index_sensors_on_device_id"
end
create_table "sequence_dependencies", id: :serial, force: :cascade do |t|
t.string "dependency_type"
t.integer "dependency_id"
@ -422,6 +433,7 @@ ActiveRecord::Schema.define(version: 20180215224528) do
add_foreign_key "points", "devices"
add_foreign_key "primary_nodes", "sequences"
add_foreign_key "sensor_readings", "devices"
add_foreign_key "sensors", "devices"
add_foreign_key "sequence_dependencies", "sequences"
add_foreign_key "tool_slots", "tools"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
RSpec.describe Api::SensorsController, type: :controller do
end

View File

@ -0,0 +1,8 @@
FactoryBot.define do
factory :sensor do
device nil
pin 1
label "MyString"
mode 1
end
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
RSpec.describe Sensor, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end