From ffbb81bade707c2964323092af0fe863e55b113b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 21 Jan 2021 18:17:38 +0100 Subject: [PATCH] Delete all posts of user --- src/helpers/account_helper.rs | 3 +++ src/helpers/posts_helper.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 6c456f3..f99c200 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -309,6 +309,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { // Delete all user comments comments_helper::delete_all_user(user_id)?; + // Delete all user posts + posts_helper::delete_all_user(user_id)?; + // TODO : continue work here Ok(()) diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index 0719de0..9557fc2 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -466,6 +466,15 @@ pub fn delete_all_group(group_id: &GroupID) -> ResultBoxError { Ok(()) } +/// Delete all the posts of a given user +pub fn delete_all_user(user_id: &UserID) -> ResultBoxError { + for post in &export_all_posts_user(user_id)? { + delete(&post)?; + } + + Ok(()) +} + /// Get all the posts that use of movie pub fn get_posts_for_movie(m: &Movie) -> ResultBoxError> { database::QueryInfo::new(POSTS_TABLE)