From f7a26239512c05f4b7262c3d77612d4c617451df Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 21 Jan 2021 18:56:35 +0100 Subject: [PATCH] Can delete all the friends of a user --- src/helpers/account_helper.rs | 3 +++ src/helpers/friends_helper.rs | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 1949bd0..278f35f 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -330,6 +330,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { // Delete all the notifications related with the user notifications_helper::delete_all_related_with_user(user_id)?; + // Delete all user friends, including friendship requests + friends_helper::delete_all_user(user_id)?; + // TODO : continue work here Ok(()) diff --git a/src/helpers/friends_helper.rs b/src/helpers/friends_helper.rs index 79fb1d6..da17020 100644 --- a/src/helpers/friends_helper.rs +++ b/src/helpers/friends_helper.rs @@ -247,6 +247,17 @@ pub fn count_requests(user_id: &UserID) -> ResultBoxError { .map(|r| r as u64) } +/// Delete all the friends of a given user +pub fn delete_all_user(user_id: &UserID) -> ResultBoxError { + database::DeleteQuery::new(FRIENDS_TABLE) + .cond_user_id("ID_personne", user_id) + .exec()?; + + database::DeleteQuery::new(FRIENDS_TABLE) + .cond_user_id("ID_amis", user_id) + .exec() +} + /// Turn a database entry into a Friend structure fn db_to_friend(row: &database::RowResult) -> ResultBoxError { Ok(Friend {