diff --git a/src/api_data/account_export_api.rs b/src/api_data/account_export_api.rs index 23d67f7..7519f8a 100644 --- a/src/api_data/account_export_api.rs +++ b/src/api_data/account_export_api.rs @@ -4,6 +4,7 @@ use serde::Serialize; use crate::api_data::comment_api::CommentAPI; +use crate::api_data::conversation_message_api::ConversationMessageAPI; use crate::api_data::movie_api::MovieAPI; use crate::api_data::post_api::PostAPI; use crate::api_data::survey_response_api::SurveyResponseAPI; @@ -22,6 +23,7 @@ pub struct AccountExportAPI { likes: Vec, survey_responses: Vec, movies: Vec, + all_conversation_messages: Vec, } impl AccountExportAPI { @@ -35,6 +37,7 @@ impl AccountExportAPI { 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), }; Ok(export) diff --git a/src/data/account_export.rs b/src/data/account_export.rs index 733cded..ea3c0b6 100644 --- a/src/data/account_export.rs +++ b/src/data/account_export.rs @@ -3,11 +3,12 @@ //! @author Pierre Hubert use crate::data::comment::Comment; +use crate::data::conversation_message::ConversationMessage; +use crate::data::movie::Movie; use crate::data::post::Post; use crate::data::survey_response::SurveyResponse; use crate::data::user::User; use crate::data::user_like::UserLike; -use crate::data::movie::Movie; pub struct AccountExport { pub user: User, @@ -16,4 +17,5 @@ pub struct AccountExport { pub likes: Vec, pub survey_responses: Vec, pub movies: Vec, + pub all_conversation_messages: Vec, } \ No newline at end of file diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index fa9a8cb..8ff5414 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -6,7 +6,7 @@ use crate::data::error::{ExecError, ResultBoxError}; use crate::data::new_account::NewAccount; use crate::data::user::UserID; use crate::data::user_token::UserAccessToken; -use crate::helpers::{comments_helper, database, likes_helper, posts_helper, survey_helper, user_helper, movies_helper}; +use crate::helpers::{comments_helper, conversations_helper, database, likes_helper, movies_helper, posts_helper, survey_helper, user_helper}; use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo}; use crate::utils::crypt_utils::{crypt_pass, rand_str}; use crate::utils::date_utils::{mysql_date, time}; @@ -200,6 +200,7 @@ pub fn export(user_id: &UserID) -> ResultBoxError { 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)?, //TODO : add other fields }; diff --git a/src/helpers/conversations_helper.rs b/src/helpers/conversations_helper.rs index b30a5ca..1b325b8 100644 --- a/src/helpers/conversations_helper.rs +++ b/src/helpers/conversations_helper.rs @@ -253,6 +253,13 @@ pub fn get_user_messages_for_conversations(conv_id: u64, user_id: &UserID) -> Re .exec(db_to_conversation_message) } +/// Export all the messages of a given user on all conversations +pub fn export_all_user_messages(user_id: &UserID) -> ResultBoxError> { + database::QueryInfo::new(CONV_MESSAGES_TABLE) + .cond_user_id("user_id", user_id) + .exec(db_to_conversation_message) +} + /// Get the entire list of messages of a given conversation pub fn get_all_messages(conv_id: u64) -> ResultBoxError> { database::QueryInfo::new(CONV_MESSAGES_TABLE)