Begin pinbinding table work

pull/686/head
Rick Carlino 2018-02-28 09:05:38 -06:00
parent 1b72f1dfd4
commit 37a714f199
10 changed files with 147 additions and 3 deletions

View File

@ -0,0 +1,33 @@
module Api
class PinBindingsController < Api::AbstractController
def index
render json: pin_bindings
end
def show
render json: pin_binding
end
def destroy
mutate PinBindings::Destroy.run(pin_binding: pin_binding)
end
def create
mutate PinBindings::Create.run(raw_json, device: current_device)
end
def update
mutate PinBindings::Update.run(raw_json, device: current_device)
end
private
def pin_bindings
PinBinding.where(device: current_device)
end
def pin_binding
@pin_binding ||= pin_bindings.find(params[:id])
end
end
end

View File

@ -0,0 +1,4 @@
class PinBinding < ApplicationRecord
belongs_to :device
belongs_to :sequence
end

View File

@ -0,0 +1,11 @@
module PinBindings
class Create < Mutations::Command
required do
model :device, class: Device
end
def execute
raise "TODO"
end
end
end

View File

@ -0,0 +1,11 @@
module PinBindings
class Destroy < Mutations::Command
required do
model :device, class: Device
end
def execute
raise "TODO"
end
end
end

View File

@ -0,0 +1,11 @@
module PinBindings
class Update < Mutations::Command
required do
model :device, class: Device
end
def execute
raise "TODO"
end
end
end

View File

@ -16,6 +16,7 @@ FarmBot::Application.routes.draw do
tools: [:create, :destroy, :index, :show, :update],
webcam_feeds: [:create, :destroy, :index, :show, :update],
device_configs: [:create, :destroy, :index, :update],
pin_bindings: [:create, :destroy, :index, :show, :update]
}.to_a.map { |(name, only)| resources name, only: only }
# Singular API Resources:

View File

@ -0,0 +1,11 @@
class CreatePinBindings < ActiveRecord::Migration[5.1]
def change
create_table :pin_bindings do |t|
t.references :device, foreign_key: true
t.integer :pin_num
t.references :sequence, foreign_key: true
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: 20180227172811) do
ActiveRecord::Schema.define(version: 20180228144634) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -33,8 +33,8 @@ ActiveRecord::Schema.define(version: 20180227172811) do
create_table "device_configs", force: :cascade do |t|
t.bigint "device_id"
t.string "key", limit: 100
t.string "value", limit: 300
t.string "key"
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["device_id"], name: "index_device_configs_on_device_id"
@ -82,6 +82,42 @@ ActiveRecord::Schema.define(version: 20180227172811) do
t.index ["device_id"], name: "index_farmware_installations_on_device_id"
end
create_table "farmware_manifest_arguments", force: :cascade do |t|
t.bigint "farmware_manifest_id"
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["farmware_manifest_id"], name: "index_farmware_manifest_arguments_on_farmware_manifest_id"
end
create_table "farmware_manifest_configs", force: :cascade do |t|
t.bigint "farmware_manifest_id"
t.string "name"
t.string "label"
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["farmware_manifest_id"], name: "index_farmware_manifest_configs_on_farmware_manifest_id"
end
create_table "farmware_manifests", force: :cascade do |t|
t.integer "quantity"
t.string "author"
t.string "description"
t.string "language"
t.string "min_os_version_major"
t.string "name"
t.string "path"
t.string "url"
t.string "uuid"
t.string "version"
t.string "zip"
t.bigint "device_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["device_id"], name: "index_farmware_manifests_on_device_id"
end
create_table "fbos_configs", force: :cascade do |t|
t.bigint "device_id"
t.datetime "created_at", null: false
@ -246,6 +282,16 @@ ActiveRecord::Schema.define(version: 20180227172811) do
t.index ["device_id"], name: "index_peripherals_on_device_id"
end
create_table "pin_bindings", force: :cascade do |t|
t.bigint "device_id"
t.integer "pin_num"
t.bigint "sequence_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["device_id"], name: "index_pin_bindings_on_device_id"
t.index ["sequence_id"], name: "index_pin_bindings_on_sequence_id"
end
create_table "plants", id: :serial, force: :cascade do |t|
t.string "openfarm_slug", limit: 280, default: "50", null: false
t.datetime "created_at"
@ -446,9 +492,13 @@ ActiveRecord::Schema.define(version: 20180227172811) do
add_foreign_key "device_configs", "devices"
add_foreign_key "edge_nodes", "sequences"
add_foreign_key "farmware_installations", "devices"
add_foreign_key "farmware_manifest_arguments", "farmware_manifests"
add_foreign_key "farmware_manifest_configs", "farmware_manifests"
add_foreign_key "log_dispatches", "devices"
add_foreign_key "log_dispatches", "logs"
add_foreign_key "peripherals", "devices"
add_foreign_key "pin_bindings", "devices"
add_foreign_key "pin_bindings", "sequences"
add_foreign_key "points", "devices"
add_foreign_key "primary_nodes", "sequences"
add_foreign_key "sensor_readings", "devices"

View File

@ -0,0 +1,7 @@
FactoryBot.define do
factory :pin_binding do
device nil
pin_num 1
sequence nil
end
end

View File

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