2020-07-13 17:12:39 +00:00
|
|
|
//! # Export account API entry
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::api_data::comment_api::CommentAPI;
|
|
|
|
use crate::api_data::post_api::PostAPI;
|
|
|
|
use crate::api_data::user_info::APIUserInfo;
|
2020-07-13 17:26:19 +00:00
|
|
|
use crate::api_data::user_like_api::UserLikeAPI;
|
2020-07-13 17:12:39 +00:00
|
|
|
use crate::data::account_export::AccountExport;
|
|
|
|
use crate::data::error::ResultBoxError;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub struct AccountExportAPI {
|
|
|
|
userID: u64,
|
|
|
|
advanced_info: APIUserInfo,
|
|
|
|
posts: Vec<PostAPI>,
|
|
|
|
comments: Vec<CommentAPI>,
|
2020-07-13 17:26:19 +00:00
|
|
|
likes: Vec<UserLikeAPI>,
|
2020-07-13 17:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AccountExportAPI {
|
|
|
|
pub fn new(export: &AccountExport) -> ResultBoxError<AccountExportAPI> {
|
|
|
|
let curr_user_id = &export.user.id;
|
|
|
|
let export = AccountExportAPI {
|
|
|
|
userID: curr_user_id.id(),
|
|
|
|
advanced_info: APIUserInfo::new_advanced_info(&curr_user_id.as_option(), &export.user)?,
|
|
|
|
posts: PostAPI::for_list(&export.posts, curr_user_id.as_option())?,
|
|
|
|
comments: CommentAPI::for_list(&export.comments, &curr_user_id.as_option())?,
|
2020-07-13 17:26:19 +00:00
|
|
|
likes: UserLikeAPI::for_list(&export.likes),
|
2020-07-13 17:12:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Ok(export)
|
|
|
|
}
|
|
|
|
}
|