1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-07-16 04:08:04 +00:00

Add responses to surveys to export

This commit is contained in:
2020-07-13 19:38:51 +02:00
parent 70d5facf4c
commit 88c45f05ac
9 changed files with 80 additions and 6 deletions

@ -5,6 +5,7 @@ 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;
@ -18,6 +19,7 @@ pub struct AccountExportAPI {
posts: Vec<PostAPI>,
comments: Vec<CommentAPI>,
likes: Vec<UserLikeAPI>,
survey_responses: Vec<SurveyResponseAPI>,
}
impl AccountExportAPI {
@ -29,6 +31,7 @@ impl AccountExportAPI {
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)

@ -48,4 +48,5 @@ pub mod res_check_security_questions_exists;
pub mod res_get_security_questions;
pub mod res_check_security_answers;
pub mod account_export_api;
pub mod user_like_api;
pub mod user_like_api;
pub mod survey_response_api;

@ -0,0 +1,32 @@
//! # Survey response API entry
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::survey_response::SurveyResponse;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct SurveyResponseAPI {
id: u64,
time_sent: u64,
userID: u64,
surveyID: u64,
choiceID: u64,
}
impl SurveyResponseAPI {
pub fn new(r: &SurveyResponse) -> SurveyResponseAPI {
SurveyResponseAPI {
id: r.id,
time_sent: r.time_sent,
userID: r.user_id.id(),
surveyID: r.survey_id,
choiceID: r.choice_id,
}
}
pub fn for_list(l: &Vec<SurveyResponse>) -> Vec<Self> {
l.iter().map(Self::new).collect()
}
}

@ -26,7 +26,7 @@ impl UserLikeAPI {
}
}
pub fn for_list(l: &Vec<UserLike>) -> Vec<UserLikeAPI> {
pub fn for_list(l: &Vec<UserLike>) -> Vec<Self> {
l.iter().map(Self::new).collect()
}
}