60 lines
1.2 KiB
Rust
60 lines
1.2 KiB
Rust
use chrono::{DateTime, Utc};
|
|
use serde::Serialize;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct BasicQuestion {
|
|
pub id: Uuid,
|
|
pub date: DateTime<Utc>,
|
|
pub active: bool,
|
|
pub text: String,
|
|
pub answers: Vec<String>,
|
|
pub suggester: Option<String>,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct FullQuestion {
|
|
#[serde(flatten)]
|
|
pub basic: BasicQuestion,
|
|
pub responses: Vec<u64>,
|
|
pub response: Option<u16>,
|
|
}
|
|
|
|
impl std::ops::Deref for FullQuestion {
|
|
type Target = BasicQuestion;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.basic
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
#[serde(tag = "type", rename_all = "snake_case")]
|
|
pub enum Question {
|
|
Basic(BasicQuestion),
|
|
Full(FullQuestion),
|
|
}
|
|
|
|
impl std::ops::Deref for Question {
|
|
type Target = BasicQuestion;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
match self {
|
|
Self::Basic(basic) => basic,
|
|
Self::Full(full) => &full.basic,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<BasicQuestion> for Question {
|
|
fn from(q: BasicQuestion) -> Self {
|
|
Self::Basic(q)
|
|
}
|
|
}
|
|
|
|
impl From<FullQuestion> for Question {
|
|
fn from(q: FullQuestion) -> Self {
|
|
Self::Full(q)
|
|
}
|
|
}
|