//! # 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::survey_response_api::SurveyResponseAPI; 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; #[derive(Serialize)] #[allow(non_snake_case)] pub struct AccountExportAPI { userID: u64, advanced_info: APIUserInfo, posts: Vec, comments: Vec, likes: Vec, survey_responses: Vec, } impl AccountExportAPI { pub fn new(export: &AccountExport) -> ResultBoxError { 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())?, likes: UserLikeAPI::for_list(&export.likes), survey_responses: SurveyResponseAPI::for_list(&export.survey_responses), }; Ok(export) } }