From cda3f231a718df2cec450218b38e8a810e2d97d8 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 10 Jan 2025 13:49:00 +0100 Subject: [PATCH] creating notifications if a shipcall is cancelled --- src/server/BreCal/impl/shipcalls.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py index df4c9b6..e6f0779 100644 --- a/src/server/BreCal/impl/shipcalls.py +++ b/src/server/BreCal/impl/shipcalls.py @@ -207,6 +207,8 @@ def PutShipcalls(schemaModel): if theshipcall is sentinel: pooledConnection.close() return json.dumps("no such record"), 404, {'Content-Type': 'application/json; charset=utf-8'} + + was_canceled = theshipcall["canceled"] # query = SQLQuery.get_shipcall_put(schemaModel) query = "UPDATE shipcall SET " @@ -257,7 +259,7 @@ def PutShipcalls(schemaModel): pquery = "SELECT id, participant_id, type FROM shipcall_participant_map where shipcall_id = ?id?" pdata = commands.query(pquery,param={"id" : schemaModel["id"]}) # existing list of assignments - # loop across passed participant ids, creating entries for those not present in pdata + # loop across passed participant ids, creating entries for those not present in pdata existing_notifications = get_notification_for_shipcall_and_type(schemaModel["id"], 1) # type = 1 is assignment @@ -304,7 +306,14 @@ def PutShipcalls(schemaModel): nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 5, ?message?)" commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : elem["participant_id"], "message" : message}) break - + + if schemaModel["canceled"] is not None: + if schemaModel["canceled"] and not was_canceled: + # create a canceled notification for all currently assigned participants + stornoNotificationQuery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 7, ?message?)" + for participant_assignment in schemaModel["participants"]: + commands.execute(stornoNotificationQuery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"], "message" : message}) + # save history data # TODO: set ETA properly # query = SQLQuery.create_sql_query_history_put()