Skip to main content

post_archiver/
author.rs

1use std::hash::Hash;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[cfg(feature = "typescript")]
7use ts_rs::TS;
8
9use crate::{AuthorId, FileMetaId, PlatformId, PostId};
10
11/// A content creator or contributor in the system
12#[cfg_attr(feature = "typescript", derive(TS))]
13#[cfg_attr(feature = "typescript", ts(export))]
14#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
15pub struct Author {
16    pub id: AuthorId,
17    pub name: String,
18    pub thumb: Option<FileMetaId>,
19    pub updated: DateTime<Utc>,
20}
21
22/// A mapping between an alternative author name and their canonical identifier
23///
24/// - Links to [`Author`](crate::author::Author) through the target ID
25/// - Used by importer modules for author resolution
26/// - Referenced in post management for author lookups
27#[cfg_attr(feature = "typescript", derive(TS))]
28#[cfg_attr(feature = "typescript", ts(export))]
29#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
30pub struct Alias {
31    /// The alias name
32    ///
33    /// Should be unique across all aliases,  
34    /// The name of the author on the platform,  
35    /// It should be never changed.
36    ///
37    /// 1. id (e.g. `18623`, `11g978qh2ki-1hhf98aq9533a`)
38    /// 2. short name (e.g. `octocat`, `jack`)
39    /// 3. full name (e.g. `The Octocat`, `Jack Dorsey`)
40    ///
41    pub source: String,
42    /// The platform this alias belongs to
43    pub platform: PlatformId,
44    /// The target author ID this alias maps to
45    pub target: AuthorId,
46    /// A link to the author's profile on the platform
47    pub link: Option<String>,
48}
49
50/// Association type that creates a many-to-many relationship between posts and tags
51#[cfg_attr(feature = "typescript", derive(TS))]
52#[cfg_attr(feature = "typescript", ts(export))]
53#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
54pub struct AuthorPost {
55    pub author: AuthorId,
56    pub post: PostId,
57}
58
59#[cfg(feature = "utils")]
60mod definitions {
61    use crate::utils::macros::as_table;
62
63    use super::*;
64
65    as_table! {
66        "authors" => Author {
67            id: "id",
68            name: "name",
69            thumb: "thumb",
70            updated: "updated",
71        }
72
73        "author_posts" => AuthorPost {
74            author: "author",
75            post: "post",
76        }
77
78        "author_aliases" => Alias {
79            source: "source",
80            platform: "platform",
81            target: "target",
82            link: "link",
83        }
84    }
85}