From 64b9497cc5b3458f8b778b7509818f1b27ae8460 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 21 Jan 2021 18:30:20 +0100 Subject: [PATCH] Can delete all the movies of a user --- src/helpers/account_helper.rs | 3 +++ src/helpers/movies_helper.rs | 9 +++++++++ 2 files changed, 12 insertions(+) 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 {