post_archiver/post/
mod.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
46
47
48
49
50
51
52
53
54
use std::hash::{Hash, Hasher};

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[cfg(feature = "typescript")]
use ts_rs::TS;

pub mod content;

pub use content::*;

use crate::{
    comment::Comment,
    id::{AuthorId, FileMetaId, PostId, PostSourceId},
    link::Link,
};

#[cfg_attr(feature = "typescript", derive(TS))]
#[cfg_attr(feature = "typescript", ts(export))]
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Post {
    pub id: PostId,
    pub author: AuthorId,
    pub source: PostSourceId,
    pub source_link: Option<Link>,
    pub title: String,
    pub content: Vec<Content>,
    pub links: Vec<Link>,
    pub thumb: Option<FileMetaId>,
    pub comments: Vec<Comment>,
    pub updated: DateTime<Utc>,
    pub published: DateTime<Utc>,
}

impl Hash for Post {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.id.hash(state);
        self.author.hash(state);
        self.source.hash(state);
        // update will not change the hash
        self.published.hash(state);
    }
}

impl PartialEq for Post {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
            && self.author == other.author
            && self.source == other.source
            && self.updated == other.updated
            && self.published == other.published
    }
}
impl Eq for Post {}