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
071c37eb
Commit
071c37eb
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
fixed device update method
parent
bd31e427
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logic/routers/DeviceRouter.py
+12
-6
12 additions, 6 deletions
src/logic/routers/DeviceRouter.py
with
12 additions
and
6 deletions
src/logic/routers/DeviceRouter.py
+
12
−
6
View file @
071c37eb
...
...
@@ -34,20 +34,26 @@ async def read_device(deviceId: int, db: Session = Depends(get_database)):
responses
=
{
400
:
{
'
description
'
:
'
Device with this name already exists
'
}},
dependencies
=
[
Depends
(
check_api_key
)])
async
def
create_device
(
device
:
Schemas
.
DeviceCreate
,
db
:
Session
=
Depends
(
get_database
)):
created
Device
=
Crud
.
get_device_by_name
(
db
,
device
.
name
)
if
created
Device
:
existing
Device
=
Crud
.
get_device_by_name
(
db
,
device
.
name
)
if
existing
Device
:
raise
HTTPException
(
status_code
=
400
,
detail
=
'
Device with this name already exists
'
)
return
Crud
.
create_device
(
db
=
db
,
device
=
device
)
@router.put
(
'
/{deviceId}
'
,
response_model
=
Schemas
.
Device
,
summary
=
'
Updates a device
'
,
responses
=
{
404
:
{
'
description
'
:
'
Device not found
'
}},
responses
=
{
400
:
{
'
description
'
:
'
Device with this name already exists
'
},
404
:
{
'
description
'
:
'
Device not found
'
}},
dependencies
=
[
Depends
(
check_api_key
)])
async
def
update_device
(
deviceId
:
int
,
device
:
Schemas
.
DeviceCreate
,
db
:
Session
=
Depends
(
get_database
)):
created
Device
=
Crud
.
get_device
_by_name
(
db
,
device
.
name
)
if
created
Device
:
existing
Device
=
Crud
.
get_device
(
db
,
device
Id
)
if
not
existing
Device
:
raise
HTTPException
(
status_code
=
404
,
detail
=
'
Device not found
'
)
existingDevice
=
Crud
.
get_device_by_name
(
db
,
device
.
name
)
if
existingDevice
:
raise
HTTPException
(
status_code
=
400
,
detail
=
'
Device with this name already exists
'
)
return
Crud
.
update_device
(
db
=
db
,
deviceId
=
deviceId
,
device
=
device
)
...
...
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