siteslib/jsonb/
comments.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
use chrono::{NaiveDateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Comments {
    pub id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<String>,
    pub data: Option<NaiveDateTime>,
}

impl Comments {
    pub fn normalize(&self) -> Self {
        Self {
            id: Option::from(if self.id.is_none() {
                Uuid::new_v4()
            } else {
                self.id.unwrap()
            }),
            comment: self.comment.clone(),
            data: Option::from(Utc::now().naive_local())
        }
    }
}