1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-30 09:16:28 +00:00
comunicapiv3/src/api_data/survey_choice_api.rs

33 lines
719 B
Rust
Raw Normal View History

2020-07-04 14:44:42 +00:00
//! # 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
}
}