testlib/jsonb/
quiz_answer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::dto::quiz_answer_response::QuizAnswerResponse;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct QuizAnswer {
    pub question_id: Uuid,
    pub answers: Vec<String>,
    pub answerer_id: Uuid,
    pub score: f32,
}

impl QuizAnswer {
    pub fn to_response(&self, task_id: Uuid) -> QuizAnswerResponse {
        QuizAnswerResponse {
            question_id: self.question_id.clone(),
            task_id: task_id.clone(),
            answers: self.answers.clone(),
            answerer_id: self.answerer_id.clone(),
            score: self.score.clone(),
        }
    }
}