1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Complete exported data

This commit is contained in:
Pierre HUBERT 2020-07-14 08:30:24 +02:00
parent df7aecc906
commit 36f879f23f
3 changed files with 21 additions and 3 deletions

View File

@ -8,6 +8,8 @@ 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::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;
@ -15,6 +17,8 @@ use crate::api_data::user_info::APIUserInfo;
use crate::api_data::user_like_api::UserLikeAPI;
use crate::data::account_export::AccountExport;
use crate::data::error::ResultBoxError;
use crate::data::group::Group;
use crate::helpers::groups_helper;
#[derive(Serialize)]
#[allow(non_snake_case)]
@ -29,6 +33,8 @@ pub struct AccountExportAPI {
all_conversation_messages: Vec<ConversationMessageAPI>,
conversations_list: Vec<ConversationAPI>,
conversations_messages: HashMap<u64, Vec<ConversationMessageAPI>>,
friends_list: Vec<FriendAPI>,
groups: Vec<GroupApi>,
}
impl AccountExportAPI {
@ -48,6 +54,14 @@ impl AccountExportAPI {
.iter()
.map(|r| (r.0.clone(), ConversationMessageAPI::for_list(r.1)))
.collect(),
friends_list: FriendAPI::from_list(&export.friends_list),
groups: export.groups
.iter()
.map(|g| groups_helper::get_info(g))
.collect::<Result<Vec<Group>, _>>()?
.iter()
.map(|g| GroupApi::new(&g, curr_user_id.as_option()))
.collect::<Result<Vec<GroupApi>, _>>()?,
};
Ok(export)

View File

@ -7,6 +7,8 @@ use std::collections::HashMap;
use crate::data::comment::Comment;
use crate::data::conversation::Conversation;
use crate::data::conversation_message::ConversationMessage;
use crate::data::friend::Friend;
use crate::data::group_id::GroupID;
use crate::data::movie::Movie;
use crate::data::post::Post;
use crate::data::survey_response::SurveyResponse;
@ -23,4 +25,6 @@ pub struct AccountExport {
pub all_conversation_messages: Vec<ConversationMessage>,
pub conversations: Vec<Conversation>,
pub conversation_messages: HashMap<u64, Vec<ConversationMessage>>,
pub friends_list: Vec<Friend>,
pub groups: Vec<GroupID>,
}

View File

@ -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, conversations_helper, database, likes_helper, movies_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::{comments_helper, conversations_helper, database, friends_helper, groups_helper, 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};
@ -203,8 +203,8 @@ pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
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
friends_list: friends_helper::GetFriendsQuery::new(user_id).exec()?,
groups: groups_helper::get_list_user(user_id, false)?,
};
// Process conversation messages