diff --git a/src/api_data/account_export_api.rs b/src/api_data/account_export_api.rs index 7519f8a..6deb8fb 100644 --- a/src/api_data/account_export_api.rs +++ b/src/api_data/account_export_api.rs @@ -1,9 +1,12 @@ //! # Export account API entry //! //! @author Pierre Hubert +use std::collections::HashMap; + use serde::Serialize; use crate::api_data::comment_api::CommentAPI; +use crate::api_data::conversation_api::ConversationAPI; use crate::api_data::conversation_message_api::ConversationMessageAPI; use crate::api_data::movie_api::MovieAPI; use crate::api_data::post_api::PostAPI; @@ -24,6 +27,8 @@ pub struct AccountExportAPI { survey_responses: Vec, movies: Vec, all_conversation_messages: Vec, + conversations_list: Vec, + conversations_messages: HashMap>, } impl AccountExportAPI { @@ -38,6 +43,11 @@ impl AccountExportAPI { 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 + .iter() + .map(|r| (r.0.clone(), ConversationMessageAPI::for_list(r.1))) + .collect(), }; Ok(export) diff --git a/src/api_data/conversation_api.rs b/src/api_data/conversation_api.rs index dcefe4e..37afce5 100644 --- a/src/api_data/conversation_api.rs +++ b/src/api_data/conversation_api.rs @@ -2,6 +2,7 @@ //! //! @author Pierre Hubert use serde::{Serialize, Serializer}; + use crate::api_data::legacy_api_bool::LegacyBool; use crate::data::conversation::Conversation; @@ -35,7 +36,6 @@ pub struct ConversationAPI { } impl ConversationAPI { - /// Construct a new Conversation instance pub fn new(conv: &Conversation) -> ConversationAPI { ConversationAPI { @@ -51,7 +51,11 @@ impl ConversationAPI { // TODO : update when call system is implemented can_have_call: false, can_have_video_call: false, - has_call_now: false + has_call_now: false, } } + + pub fn for_list(l: &Vec) -> Vec { + l.iter().map(Self::new).collect() + } } \ No newline at end of file diff --git a/src/data/account_export.rs b/src/data/account_export.rs index ea3c0b6..dda4fe0 100644 --- a/src/data/account_export.rs +++ b/src/data/account_export.rs @@ -2,7 +2,10 @@ //! //! @author Pierre Hubert +use std::collections::HashMap; + use crate::data::comment::Comment; +use crate::data::conversation::Conversation; use crate::data::conversation_message::ConversationMessage; use crate::data::movie::Movie; use crate::data::post::Post; @@ -18,4 +21,6 @@ pub struct AccountExport { pub survey_responses: Vec, pub movies: Vec, pub all_conversation_messages: Vec, + pub conversations: Vec, + pub conversation_messages: HashMap>, } \ No newline at end of file diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 8ff5414..9636e50 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -193,7 +193,7 @@ pub fn update_last_activity(user_id: &UserID) -> ResultBoxError { /// Export an account's data pub fn export(user_id: &UserID) -> ResultBoxError { - let data = AccountExport { + let mut data = AccountExport { user: user_helper::find_user_by_id(user_id)?, posts: posts_helper::export_all_posts_user(user_id)?, comments: comments_helper::export_all_user(user_id)?, @@ -201,9 +201,17 @@ pub fn export(user_id: &UserID) -> ResultBoxError { 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(), //TODO : add other fields }; + // Process conversation messages + for conv in &data.conversations { + data.conversation_messages + .insert(conv.id, conversations_helper::get_all_messages(conv.id)?); + } + Ok(data) } \ No newline at end of file