1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can delete all the friends of a user

This commit is contained in:
Pierre HUBERT 2021-01-21 18:56:35 +01:00
parent 6518ff5be8
commit f7a2623951
2 changed files with 14 additions and 0 deletions

View File

@ -330,6 +330,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError {
// Delete all the notifications related with the user // Delete all the notifications related with the user
notifications_helper::delete_all_related_with_user(user_id)?; 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 // TODO : continue work here
Ok(()) Ok(())

View File

@ -247,6 +247,17 @@ pub fn count_requests(user_id: &UserID) -> ResultBoxError<u64> {
.map(|r| r as u64) .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 /// Turn a database entry into a Friend structure
fn db_to_friend(row: &database::RowResult) -> ResultBoxError<Friend> { fn db_to_friend(row: &database::RowResult) -> ResultBoxError<Friend> {
Ok(Friend { Ok(Friend {