Skip to content

Commit

Permalink
Webapp changes to handle the geometry location columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajtxx committed Jun 6, 2024
1 parent 8ad0480 commit b935582
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/python/api/client/DAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,18 @@ def update_physical_device(device: PhysicalDevice) -> PhysicalDevice:
for name, val in vars(device).items():
if val != current_values[name]:
update_col_names.append(f'{name} = %s')
update_col_values.append(val if name not in ('source_ids', 'properties') else Json(val))
match name:
case 'location':
if val is not None:
val = AsIs(f"ST_PointFromText('POINT({val.long} {val.lat})')")

update_col_values.append(val)

case 'properties' | 'source_ids':
update_col_values.append(Json(val))

case _:
update_col_values.append(val)

logging.debug(update_col_names)
logging.debug(update_col_values)
Expand Down Expand Up @@ -589,7 +600,18 @@ def update_logical_device(device: LogicalDevice) -> LogicalDevice:
for name, val in vars(device).items():
if val != current_values[name]:
update_col_names.append(f'{name} = %s')
update_col_values.append(val if name != 'properties' else Json(val))
match name:
case 'location':
if val is not None:
val = AsIs(f"ST_PointFromText('POINT({val.long} {val.lat})')")

update_col_values.append(val)

case 'properties':
update_col_values.append(Json(val))

case _:
update_col_values.append(val)

if len(update_col_names) < 1:
return device
Expand Down
1 change: 1 addition & 0 deletions src/python/restapi/RestAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async def update_logical_device(device: LogicalDevice) -> LogicalDevice:
except dao.DAODeviceNotFound as daonf:
raise HTTPException(status_code=404, detail=daonf.msg)
except dao.DAOException as err:
logging.exception(err)
raise HTTPException(status_code=500, detail=err.msg)


Expand Down
4 changes: 3 additions & 1 deletion src/www/app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import atexit
import logging
import time
from typing import Tuple

Expand Down Expand Up @@ -646,6 +647,7 @@ def UpdateLogicalDevice():
return 'Success', 200

except requests.exceptions.HTTPError as e:
logging.exception(e)
if e.response.status_code == 403:
return f"You do not have sufficient permissions to make this change", e.response.status_code

Expand All @@ -669,7 +671,7 @@ def format_time_stamp(unformatted_time: datetime) -> str:

def format_location_string(location: Location) -> str:
formatted_location = ''
if location is not None:
if location is not None and location.lat is not None and location.long is not None:
formatted_location = f'{location.lat:.5f}, {location.long:.5f}'

return formatted_location
Expand Down

0 comments on commit b935582

Please sign in to comment.