From 625b231de52286e0ff497dce90391b6e476ec786 Mon Sep 17 00:00:00 2001 From: Sami Abuzakuk Date: Sat, 1 Nov 2025 17:05:10 +0100 Subject: [PATCH] Add backend for set all viewed and delete all --- backend/backend.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/backend/backend.py b/backend/backend.py index 2053498..1c2df59 100644 --- a/backend/backend.py +++ b/backend/backend.py @@ -242,6 +242,41 @@ def list_subscription_notifications( ] +@app.post("/subscriptions/{subscription_id}/notifications") +def set_all_notifications_viewed( + subscription_id: int, + current_user: User = Depends(get_current_user), +): + db = SessionLocal() + notifications = ( + db.query(Notification) + .filter(Notification.subscription_id == subscription_id) + .all() + ) + for notification in notifications: + notification.viewed = True + db.commit() + db.close() + return {"message": "Notifications marked as viewed"} + + +@app.delete("/subscriptions/{subscription_id}/notifications") +def remove_subscription_notifications( + subscription_id: int, current_user: User = Depends(get_current_user) +): + db = SessionLocal() + notifications = ( + db.query(Notification) + .filter(Notification.subscription_id == subscription_id) + .all() + ) + for notification in notifications: + db.delete(notification) + db.commit() + db.close() + return {"message": "Notifications removed"} + + @app.get("/notifications") def list_notifications(current_user: User = Depends(get_current_user)): db = SessionLocal()