mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-30 09:16:28 +00:00
33 lines
719 B
Rust
33 lines
719 B
Rust
//! # Survey choice API
|
|
//!
|
|
//! @author Pierre Hubert
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use serde::Serialize;
|
|
|
|
use crate::data::survey::SurveyChoice;
|
|
|
|
#[derive(Serialize)]
|
|
#[allow(non_snake_case)]
|
|
pub struct SurveyChoiceAPI {
|
|
choiceID: u64,
|
|
name: String,
|
|
responses: u64,
|
|
}
|
|
|
|
impl SurveyChoiceAPI {
|
|
pub fn new(c: &SurveyChoice) -> SurveyChoiceAPI {
|
|
SurveyChoiceAPI {
|
|
choiceID: c.id,
|
|
name: c.name.clone(),
|
|
responses: c.count,
|
|
}
|
|
}
|
|
|
|
pub fn for_list(c: &Vec<SurveyChoice>) -> HashMap<u64, SurveyChoiceAPI> {
|
|
let mut map = HashMap::with_capacity(c.len());
|
|
c.iter().for_each(|c| { map.insert(c.id, Self::new(c)); });
|
|
map
|
|
}
|
|
} |