userlib/dto/
chat_allowed_response.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
use chrono::NaiveDateTime;
use common::utils::serialize_option_naive_date;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ChatAllowedResponse {
    pub is_allowed: bool,
    #[serde(default)]
    #[serde(with = "serialize_option_naive_date")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_allowed: Option<NaiveDateTime>,
    pub teacher_ids: Vec<Uuid>,
}

impl ChatAllowedResponse {
    pub fn allowed() -> ChatAllowedResponse {
        ChatAllowedResponse {
            is_allowed: true,
            time_allowed: None,
            teacher_ids: vec![],
        }
    }

    pub fn blocked(teacher_ids: Vec<Uuid>) -> ChatAllowedResponse {
        ChatAllowedResponse {
            is_allowed: false,
            time_allowed: None,
            teacher_ids,
        }
    }
}