Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2b5d29
commit 5bd96b6
Showing
34 changed files
with
154 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,61 @@ | ||
class DevicesController < ApplicationController | ||
|
||
def index | ||
devices = Device.all | ||
render json: { status: "SUCCESS", message: "All devices currently in DB", data: devices }, status: :ok | ||
end | ||
|
||
def show | ||
devices = Device.find_by(user_id: params[:user_id]) | ||
if devices | ||
render json: { status: "SUCCESS", message: "All devices currently assigned to requested user", data: devices }, status: :ok | ||
else | ||
render json: { status: "ERROR", message: "No device found for requested user" }, status: :not_found | ||
end | ||
end | ||
|
||
def create | ||
device = Device.new(device_params) | ||
begin | ||
device.save | ||
rescue ActiveRecord::NotNullViolation => exception | ||
render json: { status: 'ERROR', message: 'Saving failed: Missing deviceName value', data: exception.message }, status: :unprocessable_entity | ||
rescue ActiveRecord::InvalidForeignKey => exception | ||
render json: { status: 'ERROR', message: 'Saving failed: user_id does not exist', data: exception.message }, status: :not_found | ||
rescue ActiveRecord::RecordNotUnique => exception | ||
render json: { status: 'ERROR', message: 'Saving failed: device_id already exists', data: exception.message }, status: :unprocessable_entity | ||
else | ||
render json: { status: 'SUCCESS', message: "Device saved", data: device }, status: :ok | ||
end | ||
end | ||
|
||
def update | ||
device = Device.find_by(device_id: params[:id]) | ||
if device | ||
if device.update_attributes(device_params) | ||
render json: { status: "SUCCESS", message: "Device updated", data: device }, status: :ok | ||
else | ||
render json: { status: "SUCCESS", message: "Device update failed", data: device.errors }, status: :unprocessable_entity | ||
end | ||
else | ||
render json: { status: "ERROR", message: "No device found for requested user" }, status: :not_found | ||
end | ||
end | ||
|
||
def destroy | ||
device = Device.find_by(device_id: params[:id]) | ||
if device | ||
device.destroy | ||
render json: { status: "SUCCESS", message: "Device deleted", data: device }, status: :ok | ||
else | ||
render json: { status: "ERROR", message: "No device found for requested user" }, status: :not_found | ||
end | ||
end | ||
|
||
private | ||
|
||
def device_params | ||
params.permit(:user_id, :device_id, :deviceName) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
begin | ||
load File.expand_path('../spring', __FILE__) | ||
rescue LoadError => e | ||
raise unless e.message.include?('spring') | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'rake' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require "pathname" | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
bundle_binstub = File.expand_path("../bundle", __FILE__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
require_relative '../config/boot' | ||
require 'rake' | ||
Rake.application.run | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("rake", "rake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) | ||
|
||
require 'bundler/setup' # Set up gems listed in the Gemfile. | ||
require 'bootsnap/setup' # Speed up boot time by caching expensive operations. | ||
#require 'bootsnap/setup' # Speed up boot time by caching expensive operations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
.../ruby/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/msgpack-1.2.4/msgpack/msgpack.bundle
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.