diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index ae11a30..6c3b2ba 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -318,6 +318,9 @@ pub fn delete(user_id: &UserID) -> ResultBoxError { // Delete all the likes created by the user likes_helper::delete_all_user(user_id)?; + // Delete all user movies + movies_helper::delete_all_user(user_id)?; + // TODO : continue work here Ok(()) diff --git a/src/helpers/movies_helper.rs b/src/helpers/movies_helper.rs index 80b42b4..1178116 100644 --- a/src/helpers/movies_helper.rs +++ b/src/helpers/movies_helper.rs @@ -43,6 +43,15 @@ pub fn delete(movie: &Movie) -> ResultBoxError { .exec() } +/// Delete all the movies of a user +pub fn delete_all_user(user_id: &UserID) -> ResultBoxError { + for movie in &get_list_user(user_id)? { + delete(movie)?; + } + + Ok(()) +} + /// Turn a database entry into a movie object fn db_to_movie(row: &database::RowResult) -> ResultBoxError { Ok(Movie {