1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Start account export

This commit is contained in:
2020-07-13 19:12:39 +02:00
parent f21636aa4e
commit 67dd29fe2d
8 changed files with 84 additions and 4 deletions

View File

@ -5,10 +5,11 @@ 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::{database, user_helper};
use crate::helpers::{database, user_helper, posts_helper, comments_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};
use crate::data::account_export::AccountExport;
/// Account helper
///
@ -188,4 +189,15 @@ pub fn update_last_activity(user_id: &UserID) -> ResultBoxError {
.cond_user_id("ID", user_id)
.set_u64("last_activity", time())
.exec()
}
/// Export an account's data
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
let 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)?
};
Ok(data)
}

View File

@ -5,6 +5,7 @@
use crate::constants::database_tables_names::COMMENTS_TABLE;
use crate::data::comment::Comment;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::helpers::{database, likes_helper};
use crate::helpers::likes_helper::LikeType;
use crate::utils::date_utils::mysql_date;
@ -40,6 +41,13 @@ pub fn get_single(comment_id: u64) -> ResultBoxError<Comment> {
.query_row(db_to_comment)
}
/// Export all the comments of a given user
pub fn export_all_user(user_id: &UserID) -> ResultBoxError<Vec<Comment>> {
database::QueryInfo::new(COMMENTS_TABLE)
.cond_user_id("ID_personne", user_id)
.exec(db_to_comment)
}
/// Turn a database entry into a comment object
fn db_to_comment(row: &database::RowResult) -> ResultBoxError<Comment> {

View File

@ -325,6 +325,15 @@ pub fn get_single(post_id: u64) -> ResultBoxError<Post> {
.query_row(db_to_post)
}
/// Get the entire list of posts of a given user + the posts created on user's page
pub fn export_all_posts_user(user_id: &UserID) -> ResultBoxError<Vec<Post>> {
database::QueryInfo::new(POSTS_TABLE)
.set_custom_where("ID_personne = ? OR ID_amis = ?")
.add_custom_where_argument_user_id(user_id)
.add_custom_where_argument_user_id(user_id)
.exec(db_to_post)
}
/// Get the access level of a user over a post
pub fn get_access_level(p: &Post, user_id: &Option<UserID>) -> ResultBoxError<PostAccessLevel> {
if user_id == &p.user_id.as_option() {