mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 08:55:16 +00:00
Add responses to surveys to export
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
use crate::constants::{PASSWORD_RESET_TOKEN_LENGTH, PASSWORD_RESET_TOKEN_LIFETIME};
|
||||
use crate::constants::database_tables_names::{USER_ACCESS_TOKENS_TABLE, USERS_TABLE};
|
||||
use crate::data::account_export::AccountExport;
|
||||
use crate::data::api_client::APIClient;
|
||||
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, posts_helper, comments_helper, likes_helper};
|
||||
use crate::helpers::{comments_helper, database, likes_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};
|
||||
use crate::data::account_export::AccountExport;
|
||||
|
||||
/// Account helper
|
||||
///
|
||||
@ -197,7 +197,8 @@ pub fn export(user_id: &UserID) -> ResultBoxError<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)?,
|
||||
likes: likes_helper::export_all_user(user_id)?
|
||||
likes: likes_helper::export_all_user(user_id)?,
|
||||
survey_responses: survey_helper::export_all_user_responses(user_id)?,
|
||||
};
|
||||
|
||||
Ok(data)
|
||||
|
@ -6,6 +6,7 @@ use crate::constants::database_tables_names::{SURVEY_CHOICES_TABLE, SURVEY_INFO_
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::new_survey::NewSurvey;
|
||||
use crate::data::survey::{Survey, SurveyChoice};
|
||||
use crate::data::survey_response::SurveyResponse;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::database;
|
||||
use crate::utils::date_utils::mysql_date;
|
||||
@ -135,6 +136,13 @@ pub fn block_new_choices_creation(survey_id: u64) -> ResultBoxError {
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Export all the responses of a given user
|
||||
pub fn export_all_user_responses(user_id: &UserID) -> ResultBoxError<Vec<SurveyResponse>> {
|
||||
database::QueryInfo::new(SURVEY_RESPONSE_TABLE)
|
||||
.cond_user_id("ID_utilisateurs", user_id)
|
||||
.exec(db_to_survey_response)
|
||||
}
|
||||
|
||||
/// Turn a database entry into a row object
|
||||
fn db_to_survey(row: &database::RowResult) -> ResultBoxError<Survey> {
|
||||
let survey_id = row.get_u64("ID")?;
|
||||
@ -157,4 +165,15 @@ fn db_to_survey_choice(row: &database::RowResult) -> ResultBoxError<SurveyChoice
|
||||
name: row.get_str("Choix")?,
|
||||
count: row.get_u64("count_choice")?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Turn a database row into a SurveyResponse object
|
||||
fn db_to_survey_response(row: &database::RowResult) -> ResultBoxError<SurveyResponse> {
|
||||
Ok(SurveyResponse {
|
||||
id: row.get_u64("ID")?,
|
||||
time_sent: row.get_date_as_time("date_envoi")?,
|
||||
user_id: row.get_user_id("ID_utilisateurs")?,
|
||||
survey_id: row.get_u64("ID_sondage")?,
|
||||
choice_id: row.get_u64("ID_sondage_choix")?,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user