Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
5b786e3a
Commit
5b786e3a
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
#8 - post route for device
parent
f6ab5b72
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/api.yml
+37
-0
37 additions, 0 deletions
docs/api.yml
src/blueprints/Devices.py
+22
-1
22 additions, 1 deletion
src/blueprints/Devices.py
src/blueprints/Measurements.py
+1
-1
1 addition, 1 deletion
src/blueprints/Measurements.py
with
60 additions
and
2 deletions
docs/api.yml
+
37
−
0
View file @
5b786e3a
...
@@ -103,6 +103,34 @@ paths:
...
@@ -103,6 +103,34 @@ paths:
type
:
array
type
:
array
items
:
items
:
$ref
:
'
#/components/schemas/Sensor'
$ref
:
'
#/components/schemas/Sensor'
/device
:
post
:
tags
:
-
device
summary
:
Adds a new device. If a device with the provided name already exists an error response is returned.
operationId
:
addDevice
security
:
-
bearerAuth
:
[]
requestBody
:
description
:
Device to add
required
:
true
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/NewDevice'
responses
:
'
200'
:
description
:
success response
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/SuccessResponse'
default
:
description
:
error response
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/ErrorResponse'
/sensors
:
/sensors
:
get
:
get
:
...
@@ -416,6 +444,15 @@ components:
...
@@ -416,6 +444,15 @@ components:
type
:
string
type
:
string
example
:
"
20.15"
example
:
"
20.15"
NewDevice
:
type
:
object
required
:
-
device
properties
:
device
:
type
:
string
example
:
"
myDevice"
SuccessResponse
:
SuccessResponse
:
required
:
required
:
-
success
-
success
...
...
This diff is collapsed.
Click to expand it.
src/blueprints/Devices.py
+
22
−
1
View file @
5b786e3a
from
flask
import
Blueprint
,
jsonify
from
flask
import
Blueprint
,
jsonify
,
request
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.Parameters
import
DeviceParameters
from
logic.RequestValidator
import
RequestValidator
,
ValidationError
from
logic.database.Database
import
Database
from
logic.database.Database
import
Database
...
@@ -42,4 +44,23 @@ def construct_blueprint(settings):
...
@@ -42,4 +44,23 @@ def construct_blueprint(settings):
return
jsonify
({
'
success
'
:
True
})
return
jsonify
({
'
success
'
:
True
})
@devices.route
(
'
/device
'
,
methods
=
[
'
POST
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
add_device
():
try
:
parameters
=
RequestValidator
.
validate
(
request
,
[
DeviceParameters
.
DEVICE
.
value
])
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
deviceName
=
parameters
[
DeviceParameters
.
DEVICE
.
value
]
existingDevice
=
database
.
deviceAccess
.
get_device_by_name
(
deviceName
)
if
existingDevice
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
A device called
"
{
deviceName
}
"
already exists (ID:
{
existingDevice
[
"
id
"
]
}
)
'
})
database
.
deviceAccess
.
add_device
(
deviceName
)
except
ValidationError
as
e
:
return
e
.
response
,
400
return
jsonify
({
'
success
'
:
True
})
return
devices
return
devices
This diff is collapsed.
Click to expand it.
src/blueprints/Measurements.py
+
1
−
1
View file @
5b786e3a
...
@@ -23,7 +23,7 @@ def construct_blueprint(settings):
...
@@ -23,7 +23,7 @@ def construct_blueprint(settings):
@measurements.route
(
'
/measurements
'
,
methods
=
[
'
POST
'
])
@measurements.route
(
'
/measurements
'
,
methods
=
[
'
POST
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
add
M
easurement
():
def
add
_m
easurement
():
try
:
try
:
parameters
=
RequestValidator
.
validate
(
request
,
DeviceParameters
.
get_values
())
parameters
=
RequestValidator
.
validate
(
request
,
DeviceParameters
.
get_values
())
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment