1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Export all conversation messages

This commit is contained in:
Pierre HUBERT 2020-07-14 07:54:40 +02:00
parent 1a7018b5e3
commit 30edf5f1a6
4 changed files with 15 additions and 2 deletions

View File

@ -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<UserLikeAPI>,
survey_responses: Vec<SurveyResponseAPI>,
movies: Vec<MovieAPI>,
all_conversation_messages: Vec<ConversationMessageAPI>,
}
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)

View File

@ -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<UserLike>,
pub survey_responses: Vec<SurveyResponse>,
pub movies: Vec<Movie>,
pub all_conversation_messages: Vec<ConversationMessage>,
}

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, 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<AccountExport> {
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
};

View File

@ -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<Vec<ConversationMessage>> {
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<Vec<ConversationMessage>> {
database::QueryInfo::new(CONV_MESSAGES_TABLE)