userlib/dto/
chat_allowed_response.rs

1use chrono::NaiveDateTime;
2use common::utils::serialize_option_naive_date;
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Serialize, Deserialize, Clone, PartialEq)]
7#[serde(rename_all = "camelCase")]
8pub struct ChatAllowedResponse {
9    pub is_allowed: bool,
10    #[serde(default)]
11    #[serde(with = "serialize_option_naive_date")]
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub time_allowed: Option<NaiveDateTime>,
14    pub teacher_ids: Vec<Uuid>,
15}
16
17impl ChatAllowedResponse {
18    pub fn allowed() -> ChatAllowedResponse {
19        ChatAllowedResponse {
20            is_allowed: true,
21            time_allowed: None,
22            teacher_ids: vec![],
23        }
24    }
25
26    pub fn blocked(teacher_ids: Vec<Uuid>) -> ChatAllowedResponse {
27        ChatAllowedResponse {
28            is_allowed: false,
29            time_allowed: None,
30            teacher_ids,
31        }
32    }
33}