mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Can cancel the response to a survey
This commit is contained in:
@ -100,6 +100,33 @@ pub fn exists(post_id: u64) -> ResultBoxError<bool> {
|
||||
.map(|r| r > 0)
|
||||
}
|
||||
|
||||
/// Cancel the response of a user to a survey
|
||||
pub fn cancel_response(user_id: &UserID, survey_id: u64) -> ResultBoxError {
|
||||
database::DeleteQuery::new(SURVEY_RESPONSE_TABLE)
|
||||
.cond_u64("ID_sondage", survey_id)
|
||||
.cond_user_id("ID_utilisateurs", user_id)
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Check out whether a choice exists or not
|
||||
pub fn choice_exists(survey_id: u64, choice_id: u64) -> ResultBoxError<bool> {
|
||||
database::QueryInfo::new(SURVEY_CHOICES_TABLE)
|
||||
.cond_u64("ID_sondage", survey_id)
|
||||
.cond_u64("ID", choice_id)
|
||||
.exec_count()
|
||||
.map(|f| f > 0)
|
||||
}
|
||||
|
||||
/// Save the new response of a user to a survey
|
||||
pub fn send_response(user_id: &UserID, survey_id: u64, choice_id: u64) -> ResultBoxError {
|
||||
database::InsertQuery::new(SURVEY_RESPONSE_TABLE)
|
||||
.add_user_id("ID_utilisateurs", user_id)
|
||||
.add_u64("ID_sondage", survey_id)
|
||||
.add_u64("ID_sondage_choix", choice_id)
|
||||
.add_str("date_envoi", &mysql_date())
|
||||
.insert_drop_result()
|
||||
}
|
||||
|
||||
/// Turn a database entry into a row object
|
||||
fn db_to_survey(row: &database::RowResult) -> ResultBoxError<Survey> {
|
||||
let survey_id = row.get_u64("ID")?;
|
||||
|
Reference in New Issue
Block a user