Skip to content

Commit 762c6c9

Browse files
authored
Merge branch 'main' into BCK-7183_update_README_clarifications
2 parents 91b2fc1 + 0726b9d commit 762c6c9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

alerts_backend/python/app.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@
7171
"aeroapi_alerts",
7272
metadata_obj,
7373
Column("id", Integer, primary_key=True, autoincrement=True),
74-
Column(
75-
"time_alert_received", DateTime(timezone=True), server_default=func.now()
76-
), # Store time in UTC that the alert was received
74+
# Store time in UTC that the alert was received
75+
Column("time_alert_received", DateTime(timezone=True), server_default=func.now()),
7776
Column("long_description", Text),
7877
Column("short_description", Text),
7978
Column("summary", Text),
@@ -125,7 +124,7 @@ def insert_into_table(data_to_insert: Dict[str, Any], table: Table) -> int:
125124
return 0
126125

127126

128-
def delete_from_table(fa_alert_id: int):
127+
def delete_from_table(fa_alert_id: int) -> int:
129128
"""
130129
Delete alert config from SQL Alert Configurations table based on FA Alert ID.
131130
Returns 0 on success, -1 otherwise.
@@ -157,7 +156,13 @@ def get_endpoint_url() -> Response:
157156

158157

159158
@app.route("/delete", methods=["POST"])
160-
def delete_alert():
159+
def delete_alert() -> Response:
160+
"""
161+
Function to delete the alert given (with key "fa_alert_id" in the payload).
162+
Deletes the given alert via AeroAPI DELETE call and then deletes it from the
163+
SQLite database. Returns JSON Response in form {"Success": True/False,
164+
"Description": <A detailed description of the response>}
165+
"""
161166
r_success: bool = False
162167
r_description: str
163168
# Process json
@@ -176,13 +181,17 @@ def delete_alert():
176181
# return to front end the error, decode and clean the response
177182
try:
178183
processed_json = result.json()
179-
r_description = f"Error code {result.status_code} with the following description: {processed_json['detail']}"
184+
r_description = f"Error code {result.status_code} with the following description for alert configuration {fa_alert_id}: {processed_json['detail']}"
180185
except json.decoder.JSONDecodeError:
181-
r_description = f"Error code {result.status_code} could not be parsed into JSON. The following is the HTML response given: {result.text}"
186+
r_description = f"Error code {result.status_code} for the alert configuration {fa_alert_id} could not be parsed into JSON. The following is the HTML response given: {result.text}"
182187
else:
183188
# Check if data was inserted into database properly
184189
if delete_from_table(fa_alert_id) == -1:
185-
r_description = "Error deleting the alert configuration from the SQL Database"
190+
r_description = (
191+
"Error deleting the alert configuration from the SQL Database - since it was deleted "
192+
"on AeroAPI but not locally, this means the alert will still be shown on the table - in order to "
193+
"properly delete the alert please look in your local Sqlite database."
194+
)
186195
else:
187196
r_success = True
188197
r_description = f"Request sent successfully, alert configuration {fa_alert_id} has been deleted"

0 commit comments

Comments
 (0)