Add backend for set all viewed and delete all
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user