From 3ee2e1843a4a674442874d44573ecb2d2468dcfc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 12 Jul 2020 14:26:39 +0200 Subject: [PATCH] Finish movie deletion implementation --- src/helpers/movies_helper.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/helpers/movies_helper.rs b/src/helpers/movies_helper.rs index 7e79770..80b42b4 100644 --- a/src/helpers/movies_helper.rs +++ b/src/helpers/movies_helper.rs @@ -7,6 +7,7 @@ use crate::data::error::ResultBoxError; use crate::data::movie::Movie; use crate::data::user::UserID; use crate::helpers::{database, posts_helper}; +use crate::utils::user_data_utils::user_data_path; /// Get the list of movies of the current pub fn get_list_user(user_id: &UserID) -> ResultBoxError> { @@ -32,9 +33,14 @@ pub fn does_user_has(user_id: &UserID, movie_id: u64) -> ResultBoxError { pub fn delete(movie: &Movie) -> ResultBoxError { posts_helper::delete_all_with_movie(movie)?; - // TODO : continue implementation + let movie_path = user_data_path(movie.uri.as_ref()); + if movie_path.exists() { + std::fs::remove_file(movie_path)?; + } - Ok(()) + database::DeleteQuery::new(MOVIES_TABLE) + .cond_u64("ID", movie.id) + .exec() } /// Turn a database entry into a movie object