Skip to content

Commit b92806a

Browse files
author
Bobby Shannon
committed
Add example Users CRUD URL endpoint
1 parent 232f688 commit b92806a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2017
-4
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ gem 'puma'
1313
gem 'redis', '~> 3.0'
1414
# Use ActiveModel has_secure_password
1515
# gem 'bcrypt', '~> 3.1.7'
16+
# Data serialization
17+
gem 'active_model_serializers'
1618

1719
# Use Capistrano for deployment
1820
# gem 'capistrano-rails', group: :development
@@ -23,6 +25,7 @@ gem 'redis', '~> 3.0'
2325
group :development, :test do
2426
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
2527
gem 'byebug'
28+
gem 'rspec-rails'
2629
end
2730

2831
group :development do

Gemfile.lock

+21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ GEM
2424
erubis (~> 2.7.0)
2525
rails-dom-testing (~> 1.0, >= 1.0.5)
2626
rails-html-sanitizer (~> 1.0, >= 1.0.2)
27+
active_model_serializers (0.9.4)
28+
activemodel (>= 3.2)
2729
activejob (5.0.0.beta2)
2830
activesupport (= 5.0.0.beta2)
2931
globalid (>= 0.3.6)
@@ -44,6 +46,7 @@ GEM
4446
builder (3.2.2)
4547
byebug (8.2.2)
4648
concurrent-ruby (1.0.0)
49+
diff-lcs (1.2.5)
4750
erubis (2.7.0)
4851
globalid (0.3.6)
4952
activesupport (>= 4.1.0)
@@ -93,6 +96,22 @@ GEM
9396
thor (>= 0.18.1, < 2.0)
9497
rake (10.5.0)
9598
redis (3.2.2)
99+
rspec-core (3.1.7)
100+
rspec-support (~> 3.1.0)
101+
rspec-expectations (3.1.2)
102+
diff-lcs (>= 1.2.0, < 2.0)
103+
rspec-support (~> 3.1.0)
104+
rspec-mocks (3.1.3)
105+
rspec-support (~> 3.1.0)
106+
rspec-rails (3.1.0)
107+
actionpack (>= 3.0)
108+
activesupport (>= 3.0)
109+
railties (>= 3.0)
110+
rspec-core (~> 3.1.0)
111+
rspec-expectations (~> 3.1.0)
112+
rspec-mocks (~> 3.1.0)
113+
rspec-support (~> 3.1.0)
114+
rspec-support (3.1.2)
96115
spring (1.6.3)
97116
sprockets (3.5.2)
98117
concurrent-ruby (~> 1.0)
@@ -114,10 +133,12 @@ PLATFORMS
114133
ruby
115134

116135
DEPENDENCIES
136+
active_model_serializers
117137
byebug
118138
puma
119139
rails (>= 5.0.0.beta2, < 5.1)
120140
redis (~> 3.0)
141+
rspec-rails
121142
spring
122143
sqlite3
123144
tzinfo-data
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Api::V1
2+
class ApiController < ApplicationController
3+
# Generic API stuff here
4+
end
5+
end
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Api::V1
2+
class JobsController < ApiController
3+
before_action :set_job, only: [:show, :update, :destroy]
4+
5+
# GET /jobs
6+
def index
7+
@jobs = Job.all
8+
9+
render json: @jobs
10+
end
11+
12+
# GET /jobs/1
13+
def show
14+
render json: @job
15+
end
16+
17+
# POST /jobs
18+
def create
19+
@job = Job.new(job_params)
20+
21+
if @job.save
22+
render json: @job, status: :created, location: @job
23+
else
24+
render json: @job.errors, status: :unprocessable_entity
25+
end
26+
end
27+
28+
# PATCH/PUT /jobs/1
29+
def update
30+
if @job.update(job_params)
31+
render json: @job
32+
else
33+
render json: @job.errors, status: :unprocessable_entity
34+
end
35+
end
36+
37+
# DELETE /jobs/1
38+
def destroy
39+
@job.destroy
40+
end
41+
42+
private
43+
# Use callbacks to share common setup or constraints between actions.
44+
def set_job
45+
@job = Job.find(params[:id])
46+
end
47+
48+
# Only allow a trusted parameter "white list" through.
49+
def job_params
50+
params.require(:job).permit(:status, :progress, :creator)
51+
end
52+
end
53+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module Api::V1
2+
class PrintersController < ApiController
3+
before_action :set_printer, only: [:show, :update, :destroy]
4+
5+
# GET /printers
6+
def index
7+
@printers = Printer.all
8+
9+
render json: @printers
10+
end
11+
12+
# GET /printers/1
13+
def show
14+
render json: @printer
15+
end
16+
17+
# POST /printers
18+
def create
19+
@printer = Printer.new(printer_params)
20+
21+
if @printer.save
22+
render json: @printer, status: :created, location: @printer
23+
else
24+
render json: @printer.errors, status: :unprocessable_entity
25+
end
26+
end
27+
28+
# PATCH/PUT /printers/1
29+
def update
30+
if @printer.update(printer_params)
31+
render json: @printer
32+
else
33+
render json: @printer.errors, status: :unprocessable_entity
34+
end
35+
end
36+
37+
# DELETE /printers/1
38+
def destroy
39+
@printer.destroy
40+
end
41+
42+
private
43+
44+
# Use callbacks to share common setup or constraints between actions.
45+
def set_printer
46+
@printer = Printer.find(params[:id])
47+
end
48+
49+
# Only allow a trusted parameter "white list" through.
50+
def printer_params
51+
params.require(:printer).permit(:make, :jobs, :manufacturer, :model, :status)
52+
end
53+
end
54+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Api::V1
2+
class PrintjobsController < ApiController
3+
before_action :set_printjob, only: [:show, :update, :destroy]
4+
5+
# GET /printjobs
6+
def index
7+
@printjobs = Printjob.all
8+
9+
render json: @printjobs
10+
end
11+
12+
# GET /printjobs/1
13+
def show
14+
render json: @printjob
15+
end
16+
17+
# POST /printjobs
18+
def create
19+
@printjob = Printjob.new(printjob_params)
20+
21+
if @printjob.save
22+
render json: @printjob, status: :created, location: @printjob
23+
else
24+
render json: @printjob.errors, status: :unprocessable_entity
25+
end
26+
end
27+
28+
# PATCH/PUT /printjobs/1
29+
def update
30+
if @printjob.update(printjob_params)
31+
render json: @printjob
32+
else
33+
render json: @printjob.errors, status: :unprocessable_entity
34+
end
35+
end
36+
37+
# DELETE /printjobs/1
38+
def destroy
39+
@printjob.destroy
40+
end
41+
42+
private
43+
# Use callbacks to share common setup or constraints between actions.
44+
def set_printjob
45+
@printjob = Printjob.find(params[:id])
46+
end
47+
48+
# Only allow a trusted parameter "white list" through.
49+
def printjob_params
50+
params.require(:printjob).permit(:status, :progress)
51+
end
52+
end
53+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Api::V1
2+
class SensordataController < ApiController
3+
before_action :set_sensordatum, only: [:show, :update, :destroy]
4+
5+
# GET /sensordata
6+
def index
7+
@sensordata = Sensordatum.all
8+
9+
render json: @sensordata
10+
end
11+
12+
# GET /sensordata/1
13+
def show
14+
render json: @sensordatum
15+
end
16+
17+
# POST /sensordata
18+
def create
19+
@sensordatum = Sensordatum.new(sensordatum_params)
20+
21+
if @sensordatum.save
22+
render json: @sensordatum, status: :created, location: @sensordatum
23+
else
24+
render json: @sensordatum.errors, status: :unprocessable_entity
25+
end
26+
end
27+
28+
# PATCH/PUT /sensordata/1
29+
def update
30+
if @sensordatum.update(sensordatum_params)
31+
render json: @sensordatum
32+
else
33+
render json: @sensordatum.errors, status: :unprocessable_entity
34+
end
35+
end
36+
37+
# DELETE /sensordata/1
38+
def destroy
39+
@sensordatum.destroy
40+
end
41+
42+
private
43+
# Use callbacks to share common setup or constraints between actions.
44+
def set_sensordatum
45+
@sensordatum = Sensordatum.find(params[:id])
46+
end
47+
48+
# Only allow a trusted parameter "white list" through.
49+
def sensordatum_params
50+
params.require(:sensordatum).permit(:type, :data)
51+
end
52+
end
53+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Api::V1
2+
class SensorsController < ApiController
3+
before_action :set_sensor, only: [:show, :update, :destroy]
4+
5+
# GET /sensors
6+
def index
7+
@sensors = Sensor.all
8+
9+
render json: @sensors
10+
end
11+
12+
# GET /sensors/1
13+
def show
14+
render json: @sensor
15+
end
16+
17+
# POST /sensors
18+
def create
19+
@sensor = Sensor.new(sensor_params)
20+
21+
if @sensor.save
22+
render json: @sensor, status: :created, location: @sensor
23+
else
24+
render json: @sensor.errors, status: :unprocessable_entity
25+
end
26+
end
27+
28+
# PATCH/PUT /sensors/1
29+
def update
30+
if @sensor.update(sensor_params)
31+
render json: @sensor
32+
else
33+
render json: @sensor.errors, status: :unprocessable_entity
34+
end
35+
end
36+
37+
# DELETE /sensors/1
38+
def destroy
39+
@sensor.destroy
40+
end
41+
42+
private
43+
# Use callbacks to share common setup or constraints between actions.
44+
def set_sensor
45+
@sensor = Sensor.find(params[:id])
46+
end
47+
48+
# Only allow a trusted parameter "white list" through.
49+
def sensor_params
50+
params.require(:sensor).permit(:type, :data, :desc, :label)
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)