Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
add update/delete safety checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrichards committed May 13, 2024
1 parent 0e7eaf4 commit ce92406
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions backend/src/new/controllers/AlertController.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def create_alert(session: AsyncSession, alert: Alert):
session.execute(insert(AlertModel).values(new_alert))

def update_alert(session: AsyncSession, alert_id: int, alert: Alert):
# updated_alert: Alert = session.query(AlertModel).filter_by(id=alert_id).first()
# if updated_alert is None:
# raise NotFoundException(id=alert_id)
query = select(AlertModel).filter_by(id=alert_id)
alert: Alert = session.execute(query).first()
if alert is None:
raise NotFoundException(id=alert_id)
dt_start_time = datetime.fromtimestamp(alert.start_time, timezone.utc)
dt_end_time = datetime.fromtimestamp(alert.end_time, timezone.utc)

Expand All @@ -83,8 +84,8 @@ def update_alert(session: AsyncSession, alert_id: int, alert: Alert):
)

def delete_alert(session: AsyncSession, alert_id: int):
# alert: Alert = session.query(AlertModel).filter_by(id=alert_id).first()
# if alert is None:
# raise NotFoundException(id=alert_id)

query = select(AlertModel).filter_by(id=alert_id)
alert: Alert = session.execute(query).first()
if alert is None:
raise NotFoundException(id=alert_id)
session.execute(delete(AlertModel).where(id=alert_id))

0 comments on commit ce92406

Please sign in to comment.