From ead879bc2114a32e954bf81516476a0afd49a640 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 12 Jul 2020 14:02:52 +0200 Subject: [PATCH] Can delete all the notifications of a given user --- src/controllers/notifications_controller.rs | 7 +++++++ src/controllers/routes.rs | 2 ++ src/helpers/notifications_helper.rs | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/controllers/notifications_controller.rs b/src/controllers/notifications_controller.rs index 8807e0c..491ab00 100644 --- a/src/controllers/notifications_controller.rs +++ b/src/controllers/notifications_controller.rs @@ -71,4 +71,11 @@ pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult { notifications_helper::delete(¬if)?; r.success("Notification deleted") +} + +/// Delete all the notifications of the current user +pub fn delete_all(r: &mut HttpRequestHandler) -> RequestResult { + notifications_helper::delete_all_user(r.user_id_ref()?)?; + + r.success("Notifications deleted.") } \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 5586239..78bb145 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -253,6 +253,8 @@ pub fn get_routes() -> Vec { Route::post("/notifications/mark_seen", Box::new(notifications_controller::mark_seen)), + Route::post("/notifications/delete_all", Box::new(notifications_controller::delete_all)), + // Movies controller Route::post("/movies/get_list", Box::new(movies_controller::get_list)), diff --git a/src/helpers/notifications_helper.rs b/src/helpers/notifications_helper.rs index 4cc42ae..8f517fb 100644 --- a/src/helpers/notifications_helper.rs +++ b/src/helpers/notifications_helper.rs @@ -21,6 +21,11 @@ pub fn delete(notification: &PartialNotification) -> ResultBoxError { .exec() } +/// Delete all the notifications of a given user +pub fn delete_all_user(user_id: &UserID) -> ResultBoxError { + delete(&PartialNotification::new().set_dest_user_id(user_id)) +} + /// Check out whether a similar notification exists for given specifications pub fn similar_exists(n: &PartialNotification) -> ResultBoxError { database::QueryInfo::new(NOTIFICATIONS_TABLE)