Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TOAR-II FastAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
esde
toar-data
TOAR-II FastAPI
Commits
cbad53cd
Commit
cbad53cd
authored
4 years ago
by
Sabine Schröder
Browse files
Options
Downloads
Patches
Plain Diff
#9
: added API for deleting fields (f. ex. roles) from stationmeta
parent
9710d33e
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#47349
passed
4 years ago
Stage: deploy
Stage: pages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
toardb/stationmeta/crud.py
+16
-8
16 additions, 8 deletions
toardb/stationmeta/crud.py
toardb/stationmeta/stationmeta.py
+7
-0
7 additions, 0 deletions
toardb/stationmeta/stationmeta.py
with
23 additions
and
8 deletions
toardb/stationmeta/crud.py
+
16
−
8
View file @
cbad53cd
...
@@ -4,7 +4,7 @@ Create, Read, Update, Delete functionality
...
@@ -4,7 +4,7 @@ Create, Read, Update, Delete functionality
"""
"""
from
sqlalchemy
import
cast
,
Text
,
insert
,
update
from
sqlalchemy
import
cast
,
Text
,
insert
,
update
,
delete
from
typing
import
List
from
typing
import
List
from
geoalchemy2.types
import
Geometry
from
geoalchemy2.types
import
Geometry
from
sqlalchemy.orm
import
Session
from
sqlalchemy.orm
import
Session
...
@@ -207,18 +207,11 @@ def patch_stationmeta(db: Session, station_id: int, stationmeta: StationmetaPatc
...
@@ -207,18 +207,11 @@ def patch_stationmeta(db: Session, station_id: int, stationmeta: StationmetaPatc
db_object
=
get_unique_stationmeta_role
(
db
,
db_role
.
role
,
db_role
.
contact_id
,
db_role
.
status
)
db_object
=
get_unique_stationmeta_role
(
db
,
db_role
.
role
,
db_role
.
contact_id
,
db_role
.
status
)
if
db_object
:
if
db_object
:
role_id
=
db_object
.
id
role_id
=
db_object
.
id
print
(
"
found role_id:
"
,
role_id
)
else
:
else
:
print
(
"
did not find role: now inserting new role
"
)
print
(
r
)
print
(
db_role
.
role
)
print
(
db_role
.
status
)
print
(
db_role
.
contact_id
)
db
.
add
(
db_role
)
db
.
add
(
db_role
)
db
.
commit
()
db
.
commit
()
db
.
refresh
(
db_role
)
db
.
refresh
(
db_role
)
role_id
=
db_role
.
id
role_id
=
db_role
.
id
print
(
"
did not find role: inserted new role_id
"
,
role_id
)
db
.
execute
(
insert
(
stationmeta_core_stationmeta_roles_table
).
values
(
station_id
=
station_id
,
role_id
=
role_id
))
db
.
execute
(
insert
(
stationmeta_core_stationmeta_roles_table
).
values
(
station_id
=
station_id
,
role_id
=
role_id
))
db
.
commit
()
db
.
commit
()
# store annotations and update association table
# store annotations and update association table
...
@@ -279,3 +272,18 @@ def patch_stationmeta(db: Session, station_id: int, stationmeta: StationmetaPatc
...
@@ -279,3 +272,18 @@ def patch_stationmeta(db: Session, station_id: int, stationmeta: StationmetaPatc
# there's a mismatch with coordinates --> how to automatically switch back and forth?!
# there's a mismatch with coordinates --> how to automatically switch back and forth?!
db_stationmeta
.
coordinates
=
tmp_coordinates
db_stationmeta
.
coordinates
=
tmp_coordinates
return
db_stationmeta
return
db_stationmeta
def
delete_stationmeta_field
(
db
:
Session
,
station_id
:
int
,
keyword
:
str
):
if
keyword
==
'
roles
'
:
db
.
execute
(
delete
(
stationmeta_core_stationmeta_roles_table
).
where
(
stationmeta_core_stationmeta_roles_table
.
c
.
station_id
==
station_id
))
# stationmeta_core_stationmeta_roles_table.delete().where(stationmeta_core_stationmeta_roles_table.c.station_id==station_id)
# problem with automatic conversion of coordinates (although not explicitly fetched from database)
# ==> next two lines are a workaround
db_stationmeta
=
db
.
query
(
models
.
StationmetaCore
).
get
(
station_id
)
tmp_coordinates
=
db_stationmeta
.
coordinates
db_stationmeta
.
coordinates
=
get_geom_from_coordinates
(
db_stationmeta
.
coordinates
)
db
.
commit
()
# there's a mismatch with coordinates --> how to automatically switch back and forth?!
db_stationmeta
.
coordinates
=
tmp_coordinates
return
db_stationmeta
This diff is collapsed.
Click to expand it.
toardb/stationmeta/stationmeta.py
+
7
−
0
View file @
cbad53cd
...
@@ -65,3 +65,10 @@ def patch_stationmeta_core(station_code: str, stationmeta: schemas.StationmetaPa
...
@@ -65,3 +65,10 @@ def patch_stationmeta_core(station_code: str, stationmeta: schemas.StationmetaPa
if
db_stationmeta
is
None
:
if
db_stationmeta
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"
Station for patching not found.
"
)
raise
HTTPException
(
status_code
=
404
,
detail
=
"
Station for patching not found.
"
)
return
crud
.
patch_stationmeta
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
stationmeta
=
stationmeta
)
return
crud
.
patch_stationmeta
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
stationmeta
=
stationmeta
)
@router.patch
(
'
/stationmeta/delete_field/{station_code}
'
,
response_model
=
schemas
.
StationmetaPatch
)
def
patch_stationmeta_core
(
station_code
:
str
,
field
:
str
,
db
:
Session
=
Depends
(
get_db
)):
db_stationmeta
=
crud
.
get_stationmeta
(
db
,
station_code
=
station_code
)
if
db_stationmeta
is
None
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"
Station for deleting field not found.
"
)
return
crud
.
delete_stationmeta_field
(
db
=
db
,
station_id
=
db_stationmeta
.
id
,
keyword
=
field
)
This diff is collapsed.
Click to expand it.
Sabine Schröder
@schroeder5
mentioned in issue
#9 (closed)
·
4 years ago
mentioned in issue
#9 (closed)
mentioned in issue #9
Toggle commit list
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