diff --git a/src/api_data/account_export_api.rs b/src/api_data/account_export_api.rs index fee458a..0422963 100644 --- a/src/api_data/account_export_api.rs +++ b/src/api_data/account_export_api.rs @@ -11,7 +11,6 @@ use crate::api_data::conversation_message_api::ConversationMessageAPI; use crate::api_data::entities_constructor::EntitiesConstructor; use crate::api_data::friend_api::FriendAPI; use crate::api_data::group_api::GroupApi; -use crate::api_data::movie_api::MovieAPI; use crate::api_data::post_api::PostAPI; use crate::api_data::survey_response_api::SurveyResponseAPI; use crate::api_data::user_info::APIUserInfo; @@ -32,7 +31,6 @@ pub struct AccountExportAPI { comments: Vec, likes: Vec, survey_responses: Vec, - movies: Vec, all_conversation_messages: Vec, conversations_list: Vec, conversations_messages: HashMap>, @@ -51,7 +49,6 @@ impl AccountExportAPI { comments: CommentAPI::for_list(&export.comments, &curr_user_id.as_option())?, likes: UserLikeAPI::for_list(&export.likes), survey_responses: SurveyResponseAPI::for_list(&export.survey_responses), - movies: MovieAPI::for_list(&export.movies), all_conversation_messages: ConversationMessageAPI::for_list(&export.all_conversation_messages), conversations_list: ConversationAPI::for_list(&export.conversations), conversations_messages: export.conversation_messages diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index 069fe76..faf136d 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -31,7 +31,6 @@ pub mod group_member_api; pub mod friend_api; pub mod friendship_status_api; pub mod post_api; -pub mod movie_api; pub mod survey_choice_api; pub mod survey_api; pub mod comment_api; diff --git a/src/api_data/movie_api.rs b/src/api_data/movie_api.rs deleted file mode 100644 index bdaf495..0000000 --- a/src/api_data/movie_api.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! # Movie API information -//! -//! @author Pierre Hubert -use serde::Serialize; - -use crate::data::movie::Movie; -use crate::utils::user_data_utils::user_data_url; - -#[derive(Serialize)] -#[allow(non_snake_case)] -pub struct MovieAPI { - id: u64, - uri: String, - url: String, - userID: u64, - name: String, - file_type: String, - size: usize, -} - -impl MovieAPI { - /// Construct a new instance of movie - pub fn new(m: &Movie) -> MovieAPI { - MovieAPI { - id: m.id, - uri: m.uri.clone(), - url: user_data_url(m.uri.as_str()), - userID: m.user_id.id(), - name: m.name.clone(), - file_type: m.file_type.clone(), - size: m.size, - } - } - - pub fn for_list(l: &Vec) -> Vec { - l.iter().map(Self::new).collect() - } -} \ No newline at end of file diff --git a/src/api_data/post_api.rs b/src/api_data/post_api.rs index e142dd6..a9e3aae 100644 --- a/src/api_data/post_api.rs +++ b/src/api_data/post_api.rs @@ -4,12 +4,11 @@ use serde::Serialize; use crate::api_data::comment_api::CommentAPI; -use crate::api_data::movie_api::MovieAPI; use crate::api_data::survey_api::SurveyAPI; use crate::data::error::ResultBoxError; use crate::data::post::{Post, PostKind}; use crate::data::user::UserID; -use crate::helpers::{comments_helper, likes_helper, movies_helper, posts_helper, survey_helper}; +use crate::helpers::{comments_helper, likes_helper, posts_helper, survey_helper}; use crate::helpers::likes_helper::LikeType; use crate::utils::user_data_utils::user_data_url; @@ -38,10 +37,6 @@ pub struct PostAPI { link_description: Option, link_image: Option, - // Movie specific - video_id: Option, - video_info: Option, - // Countdown timer specific time_end: Option, @@ -82,10 +77,6 @@ impl PostAPI { link_description: None, link_image: None, - // Movie specific - video_id: None, - video_info: None, - // Countdown timer-specific time_end: None, @@ -120,11 +111,6 @@ impl PostAPI { post.link_image = link.image.clone(); } - PostKind::POST_KIND_MOVIE(movie_id) => { - post.video_id = Some(*movie_id); - post.video_info = Some(MovieAPI::new(&movies_helper::get_info(*movie_id)?)) - } - PostKind::POST_KIND_COUNTDOWN(time_end) => post.time_end = Some(*time_end), PostKind::POST_KIND_SURVEY => diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index 81d7592..2755c14 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -16,7 +16,6 @@ pub mod comments_controller; pub mod likes_controller; pub mod surveys_controller; pub mod notifications_controller; -pub mod movies_controller; pub mod virtual_directory_controller; pub mod web_app_controller; pub mod calls_controller; diff --git a/src/controllers/movies_controller.rs b/src/controllers/movies_controller.rs deleted file mode 100644 index 55a01a7..0000000 --- a/src/controllers/movies_controller.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! # Movies controller -//! -//! @author Pierre Hubert - -use crate::api_data::movie_api::MovieAPI; -use crate::controllers::routes::RequestResult; -use crate::data::base_request_handler::BaseRequestHandler; -use crate::data::http_request_handler::HttpRequestHandler; -use crate::helpers::movies_helper; - -/// Get the list of movies of the current user -pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { - let list = movies_helper::get_list_user(r.user_id_ref()?)?; - - r.set_response(MovieAPI::for_list(&list)) -} - -/// Remove a movie -pub fn delete(r: &mut HttpRequestHandler) -> RequestResult { - let movie_id = r.post_movie_id("movieID")?; - - movies_helper::delete(&movies_helper::get_info(movie_id)?)?; - - r.success("Movie deleted.") -} \ No newline at end of file diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index fdf2df2..a0480ad 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -158,13 +158,6 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { PostKind::POST_KIND_YOUTUBE(youtube) } - // Movies posts - "movie" => { - let movie_id = r.post_movie_id("movieID")?; - - PostKind::POST_KIND_MOVIE(movie_id) - } - // Weblink posts "weblink" => { let url = r.post_url_opt("url", true)? diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index a0e55a9..b2af591 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -1,6 +1,6 @@ use std::error::Error; -use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; +use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; use crate::controllers::routes::Method::{GET, POST}; use crate::data::http_request_handler::HttpRequestHandler; @@ -277,11 +277,6 @@ pub fn get_routes() -> Vec { Route::post("/notifications/delete_all", Box::new(notifications_controller::delete_all)), - // Movies controller - Route::post("/movies/get_list", Box::new(movies_controller::get_list)), - Route::post("/movies/delete", Box::new(movies_controller::delete)), - - // Virtual directory controller Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)), Route::post("/virtualDirectory/find", Box::new(virtual_directory_controller::find)), diff --git a/src/data/account_export.rs b/src/data/account_export.rs index 196ace2..d19c0d1 100644 --- a/src/data/account_export.rs +++ b/src/data/account_export.rs @@ -10,7 +10,6 @@ use crate::data::conversation_message::ConversationMessage; use crate::data::error::ResultBoxError; use crate::data::friend::Friend; use crate::data::group_id::GroupID; -use crate::data::movie::Movie; use crate::data::post::{Post, PostPageKind}; use crate::data::survey_response::SurveyResponse; use crate::data::user::{User, UserID}; @@ -23,7 +22,6 @@ pub struct AccountExport { pub comments: Vec, pub likes: Vec, pub survey_responses: Vec, - pub movies: Vec, pub all_conversation_messages: Vec, pub conversations: Vec, pub conversation_messages: HashMap>, diff --git a/src/data/base_request_handler.rs b/src/data/base_request_handler.rs index 91e0e07..29d06ca 100644 --- a/src/data/base_request_handler.rs +++ b/src/data/base_request_handler.rs @@ -20,7 +20,7 @@ use crate::data::group::GroupAccessLevel; use crate::data::group_id::GroupID; use crate::data::post::{Post, PostAccessLevel}; use crate::data::user::UserID; -use crate::helpers::{account_helper, comments_helper, conversations_helper, custom_emojies_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper}; +use crate::helpers::{account_helper, comments_helper, conversations_helper, custom_emojies_helper, friends_helper, groups_helper, posts_helper, user_helper, virtual_directory_helper}; use crate::helpers::virtual_directory_helper::VirtualDirType; use crate::utils::pdf_utils::is_valid_pdf; use crate::utils::string_utils::{check_emoji_code, check_string_before_insert, check_url, remove_html_nodes}; @@ -536,17 +536,6 @@ pub trait BaseRequestHandler { Ok(comment) } - /// Get the ID of a movie included in the request - fn post_movie_id(&mut self, name: &str) -> ResultBoxError { - let movie_id = self.post_u64(name)?; - - if !movies_helper::does_user_has(self.user_id_ref()?, movie_id)? { - self.forbidden("You are not authorized to use this movie!".to_string())?; - } - - Ok(movie_id) - } - /// Get a content of a post and satinize it fn post_content(&mut self, name: &str, min_len: usize, required: bool) -> ResultBoxError { let content = self.post_string_opt(name, min_len, required)?; diff --git a/src/data/post.rs b/src/data/post.rs index e906de3..3155825 100644 --- a/src/data/post.rs +++ b/src/data/post.rs @@ -96,10 +96,10 @@ pub enum PostKind { POST_KIND_IMAGE(PostFile), POST_KIND_WEBLINK(PostWebLink), POST_KIND_PDF(PostFile), - POST_KIND_MOVIE(u64), - // The ID of the movie + + /// Countdown. Value : end time POST_KIND_COUNTDOWN(u64), - // End time + POST_KIND_SURVEY, POST_KIND_YOUTUBE(String), } @@ -111,7 +111,6 @@ impl PostKind { PostKind::POST_KIND_IMAGE(_) => "image", PostKind::POST_KIND_WEBLINK(_) => "weblink", PostKind::POST_KIND_PDF(_) => "pdf", - PostKind::POST_KIND_MOVIE(_) => "movie", PostKind::POST_KIND_COUNTDOWN(_) => "countdown", PostKind::POST_KIND_SURVEY => "survey", PostKind::POST_KIND_YOUTUBE(_) => "youtube", diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 94a3079..8da2abe 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -12,7 +12,7 @@ use crate::data::new_account::NewAccount; use crate::data::security_settings::SecuritySettings; use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus}; use crate::data::user_token::UserAccessToken; -use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, movies_helper, notifications_helper, posts_helper, survey_helper, user_helper}; +use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, survey_helper, user_helper}; use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo}; use crate::helpers::events_helper::Event; use crate::helpers::likes_helper::LikeType; @@ -287,7 +287,6 @@ pub fn export(user_id: &UserID) -> ResultBoxError { comments: comments_helper::export_all_user(user_id)?, likes: likes_helper::export_all_user(user_id)?, survey_responses: survey_helper::export_all_user_responses(user_id)?, - movies: movies_helper::get_list_user(user_id)?, all_conversation_messages: conversations_helper::export_all_user_messages(user_id)?, conversations: conversations_helper::get_list_user(user_id)?, conversation_messages: Default::default(), @@ -324,9 +323,6 @@ 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)?; - // Delete all conversation messages conversations_helper::delete_all_user_messages(user_id)?; diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index 683f516..6f66c07 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -11,7 +11,6 @@ pub mod groups_helper; pub mod posts_helper; pub mod conversations_helper; pub mod virtual_directory_helper; -pub mod movies_helper; pub mod survey_helper; pub mod comments_helper; pub mod notifications_helper; diff --git a/src/helpers/movies_helper.rs b/src/helpers/movies_helper.rs deleted file mode 100644 index 79e6810..0000000 --- a/src/helpers/movies_helper.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! # Movies helper -//! -//! @author Pierre Hubert - -use crate::constants::database_tables_names::MOVIES_TABLE; -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> { - database::QueryInfo::new(MOVIES_TABLE) - .cond_user_id("ID_user", user_id) - .set_order("ID DESC") - .exec(db_to_movie) -} - -/// Get all movies -pub fn get_all() -> ResultBoxError> { - database::QueryInfo::new(MOVIES_TABLE) - .exec(db_to_movie) -} - -/// Get information about a single movie -pub fn get_info(movie_id: u64) -> ResultBoxError { - database::QueryInfo::new(MOVIES_TABLE) - .cond_u64("ID", movie_id) - .query_row(db_to_movie) -} - -/// Check out whether a user own a movie or not -pub fn does_user_has(user_id: &UserID, movie_id: u64) -> ResultBoxError { - Ok(get_info(movie_id).map(|m| &m.user_id == user_id).unwrap_or(false)) -} - -/// Remove permanently a movie from the database -pub fn delete(movie: &Movie) -> ResultBoxError { - posts_helper::delete_all_with_movie(movie)?; - - let movie_path = user_data_path(movie.uri.as_ref()); - if movie_path.exists() { - std::fs::remove_file(movie_path)?; - } - - database::DeleteQuery::new(MOVIES_TABLE) - .cond_u64("ID", movie.id) - .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 { - id: row.get_u64("ID")?, - user_id: row.get_user_id("ID_user")?, - name: row.get_str("nom_video")?, - uri: row.get_str("URL")?, - file_type: row.get_str("file_type")?, - size: row.get_usize("size")?, - }) -} \ No newline at end of file diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index 5d0eb0c..28f1130 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -10,7 +10,7 @@ use crate::data::group_id::GroupID; use crate::data::group_member::GroupMembershipLevel; use crate::data::movie::Movie; use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink}; -use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_MOVIE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE}; +use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE}; use crate::data::user::UserID; use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, survey_helper, user_helper}; use crate::helpers::likes_helper::LikeType; @@ -45,7 +45,6 @@ impl PostKind { POST_KIND_IMAGE(_) => "image", POST_KIND_WEBLINK(_) => "webpage_link", POST_KIND_PDF(_) => "pdf", - POST_KIND_MOVIE(_) => "video", POST_KIND_COUNTDOWN(_) => "count_down", POST_KIND_SURVEY => "sondage", POST_KIND_YOUTUBE(_) => "youtube", @@ -93,11 +92,6 @@ pub fn create(p: &Post) -> ResultBoxError { .add_str("type", "youtube"); } - // Movie post - POST_KIND_MOVIE(id) => { - insert_query = insert_query.add_u64("idvideo", *id); - } - // Weblink POST_KIND_WEBLINK(weblink) => { insert_query = insert_query @@ -540,8 +534,6 @@ fn db_to_post(res: &database::RowResult) -> ResultBoxError { "pdf" => post.kind = POST_KIND_PDF(file?), - "video" => post.kind = POST_KIND_MOVIE(res.get_u64("idvideo")?), - "count_down" => post.kind = POST_KIND_COUNTDOWN(res.get_u64("time_end").unwrap_or(0)), "sondage" => post.kind = POST_KIND_SURVEY, diff --git a/src/main.rs b/src/main.rs index 5b9cb74..3ad1933 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use comunic_server::controllers::server; use comunic_server::data::config::{conf, Config}; -use comunic_server::helpers::{database, movies_helper}; +use comunic_server::helpers::database; #[actix_rt::main] async fn main() -> std::io::Result<()> { @@ -15,12 +15,6 @@ async fn main() -> std::io::Result<()> { // Connect to the database database::connect(&conf().database).expect("Could not connect to database!"); - // TODO : remove after application - // Remove all movies - for movie in movies_helper::get_all().unwrap() { - movies_helper::delete(&movie).unwrap(); - } - // Start the server server::start_server(conf()).await }