use serde_derive::{Serialize, Deserialize};
use chrono::prelude::*;
use crate::utils;
use crate::models::status::Status;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Reply {
pub message: String,
#[serde(default = "default_anonym")]
pub anonymous: bool,
#[serde(default = "Status::pending")]
pub status: Status,
#[serde(default = "default_remark")]
pub remarks: String,
#[serde(default = "String::new")]
pub unique_id: String,
#[serde(default = "String::new")]
pub parent_id: String,
#[serde(default = "String::new")]
pub comment_id: String,
pub level: u32,
#[serde(default = "String::new")]
pub user_id: String,
#[serde(default = "String::new")]
pub created_on: String,
#[serde(default = "String::new")]
pub updated_on: String,
#[serde(default = "String::new")]
pub deleted_on: String,
}
fn default_anonym() -> bool {
false
}
fn default_remark() -> String {
"New Reply".to_string()
}
impl PartialEq for Reply {
fn eq(&self, other: &Self) -> bool {
(self.message == other.message) &&
(self.status == other.status) &&
(self.parent_id == other.parent_id) &&
(self.comment_id == other.comment_id) &&
(self.level == other.level) &&
(self.user_id == other.user_id)
}
}
impl Eq for Reply {}
pub fn assign_uid(reply: &mut Reply) {
reply.unique_id = utils::unique_id();
}
pub fn assign_created_date(reply: &mut Reply) {
reply.created_on = Local::now().to_string();
}
pub fn assign_updated_date(reply: &mut Reply) {
reply.updated_on = Local::now().to_string();
}
pub fn assign_deleted_date(reply: &mut Reply) {
reply.deleted_on = Local::now().to_string();
}