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
a28bddd9
Commit
a28bddd9
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
added route to delete a device
parent
335b5c9c
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
src/logic/databaseNew/Crud.py
+5
-0
5 additions, 0 deletions
src/logic/databaseNew/Crud.py
src/logic/databaseNew/Schemas.py
+4
-0
4 additions, 0 deletions
src/logic/databaseNew/Schemas.py
src/routers/DeviceRouter.py
+13
-0
13 additions, 0 deletions
src/routers/DeviceRouter.py
with
22 additions
and
0 deletions
src/logic/databaseNew/Crud.py
+
5
−
0
View file @
a28bddd9
...
@@ -23,6 +23,11 @@ def create_device(db: Session, device: Schemas.DeviceCreate):
...
@@ -23,6 +23,11 @@ def create_device(db: Session, device: Schemas.DeviceCreate):
return
dbDevice
return
dbDevice
def
delete_device
(
db
:
Session
,
device
:
Schemas
.
Device
):
db
.
delete
(
device
)
db
.
commit
()
def
get_sensors
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
def
get_sensors
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
return
db
.
query
(
Models
.
Sensor
).
offset
(
skip
).
limit
(
limit
).
all
()
return
db
.
query
(
Models
.
Sensor
).
offset
(
skip
).
limit
(
limit
).
all
()
...
...
This diff is collapsed.
Click to expand it.
src/logic/databaseNew/Schemas.py
+
4
−
0
View file @
a28bddd9
...
@@ -3,6 +3,10 @@ from typing import List
...
@@ -3,6 +3,10 @@ from typing import List
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
class
Status
(
BaseModel
):
message
:
str
class
SensorBase
(
BaseModel
):
class
SensorBase
(
BaseModel
):
id
:
int
id
:
int
name
:
str
name
:
str
...
...
This diff is collapsed.
Click to expand it.
src/routers/DeviceRouter.py
+
13
−
0
View file @
a28bddd9
...
@@ -5,6 +5,7 @@ from sqlalchemy.orm import Session
...
@@ -5,6 +5,7 @@ from sqlalchemy.orm import Session
from
Dependencies
import
get_database
from
Dependencies
import
get_database
from
logic.databaseNew
import
Schemas
,
Crud
from
logic.databaseNew
import
Schemas
,
Crud
from
logic.databaseNew.Schemas
import
Status
router
=
APIRouter
(
router
=
APIRouter
(
prefix
=
'
/device
'
,
prefix
=
'
/device
'
,
...
@@ -37,3 +38,15 @@ async def create_user(device: Schemas.DeviceCreate, db: Session = Depends(get_da
...
@@ -37,3 +38,15 @@ async def create_user(device: Schemas.DeviceCreate, db: Session = Depends(get_da
if
createdDevice
:
if
createdDevice
:
raise
HTTPException
(
status_code
=
400
,
detail
=
'
Device with this name already exists
'
)
raise
HTTPException
(
status_code
=
400
,
detail
=
'
Device with this name already exists
'
)
return
Crud
.
create_device
(
db
=
db
,
device
=
device
)
return
Crud
.
create_device
(
db
=
db
,
device
=
device
)
@router.delete
(
'
/{deviceId}
'
,
response_model
=
Status
,
summary
=
'
Gets a specific device
'
,
responses
=
{
404
:
{
'
description
'
:
'
Device not found
'
}})
async
def
read_device
(
deviceId
:
int
,
db
:
Session
=
Depends
(
get_database
)):
device
=
Crud
.
get_device
(
db
,
deviceId
=
deviceId
)
if
device
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
'
Device not found
'
)
Crud
.
delete_device
(
db
,
device
)
return
Status
(
message
=
f
"
Deleted device
{
device
.
id
}
"
)
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