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
f6ab5b72
Commit
f6ab5b72
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
delete route for device
parent
851a6f39
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/api.yml
+27
-0
27 additions, 0 deletions
docs/api.yml
src/blueprints/Devices.py
+17
-0
17 additions, 0 deletions
src/blueprints/Devices.py
src/logic/database/DeviceAccess.py
+4
-0
4 additions, 0 deletions
src/logic/database/DeviceAccess.py
with
48 additions
and
0 deletions
docs/api.yml
+
27
−
0
View file @
f6ab5b72
...
...
@@ -54,6 +54,33 @@ paths:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Device'
delete
:
tags
:
-
device
summary
:
Deletes a specific device. All correspondig sensors and measurements will be deleted too.
operationId
:
deleteDevice
security
:
-
bearerAuth
:
[]
parameters
:
-
in
:
path
name
:
deviceID
description
:
The device id
required
:
true
schema
:
type
:
integer
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'
/device/{deviceID}/sensors
:
get
:
tags
:
...
...
This diff is collapsed.
Click to expand it.
src/blueprints/Devices.py
+
17
−
0
View file @
f6ab5b72
from
flask
import
Blueprint
,
jsonify
from
logic.AuthenticationWrapper
import
require_api_key
from
logic.database.Database
import
Database
...
...
@@ -25,4 +26,20 @@ def construct_blueprint(settings):
return
jsonify
(
database
.
sensorAccess
.
get_all_sensors_for_device
(
deviceID
))
@devices.route
(
'
/device/<int:deviceID>
'
,
methods
=
[
'
DELETE
'
])
@require_api_key
(
password
=
settings
[
'
api
'
][
'
key
'
])
def
delete_device
(
deviceID
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
if
not
database
.
deviceAccess
.
get_device
(
deviceID
):
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No device with id
"
{
deviceID
}
"
existing
'
})
sensors
=
database
.
sensorAccess
.
get_all_sensors_for_device
(
deviceID
)
for
sensor
in
sensors
:
database
.
measurementAccess
.
delete_measurements_for_sensor
(
sensor
[
'
id
'
])
database
.
sensorAccess
.
delete_sensor
(
sensor
[
'
id
'
])
database
.
deviceAccess
.
delete_device
(
deviceID
)
return
jsonify
({
'
success
'
:
True
})
return
devices
This diff is collapsed.
Click to expand it.
src/logic/database/DeviceAccess.py
+
4
−
0
View file @
f6ab5b72
...
...
@@ -28,3 +28,7 @@ class DeviceAccess(DatabaseAccess):
def
add_device
(
self
,
deviceName
:
str
):
LOGGER
.
debug
(
f
'
Inserting new device
"
{
deviceName
}
"'
)
self
.
_query
(
f
'
INSERT INTO
{
self
.
TABLE_NAME
}
(name) VALUES(?)
'
,
deviceName
,
fetch_type
=
FetchType
.
NONE
)
def
delete_device
(
self
,
deviceID
:
int
):
LOGGER
.
debug
(
f
'
Deleting device
"
{
deviceID
}
"'
)
self
.
_query
(
f
'
DELETE FROM
{
self
.
TABLE_NAME
}
WHERE id = ?
'
,
deviceID
,
fetch_type
=
FetchType
.
NONE
)
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