assignmentlib/dto/
attempt_request.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use chrono::NaiveDateTime;
use common::utils::serialize_option_naive_date;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::dto::answer_group_request::AnswerGroupRequest;

use crate::enums::attempt_status::AttemptStatus;

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AttemptRequest {
    pub id: Option<Uuid>,
    #[serde(default)]
    #[serde(with = "serialize_option_naive_date")]
    pub start_time: Option<NaiveDateTime>,
    #[serde(default)]
    #[serde(with = "serialize_option_naive_date")]
    pub end_time: Option<NaiveDateTime>,
    #[serde(rename = "user")]
    pub user_t: Uuid,
    pub task: Uuid,
    pub user_role: Uuid,
    pub answers: Option<Vec<AnswerGroupRequest>>,
    pub status: Option<AttemptStatus>,
    pub paused: Option<bool>,
}

impl AttemptRequest {
    pub fn equal(&self, other: &AttemptRequest) -> bool {
        let mut eq = true;
        eq &= self.id == other.id;
        eq &= self.start_time == other.start_time;
        eq &= self.end_time == other.end_time;
        eq &= self.task == other.task;
        eq &= self.user_t == other.user_t;
        eq &= self.user_role == other.user_role;
        eq &= AnswerGroupRequest::vec_equal(
            &self.answers.clone().unwrap(),
            &other.answers.clone().unwrap(),
        );
        eq &= self.start_time == other.start_time;
        eq &= self.paused == other.paused;
        eq
    }
}