post_archiver/
tag.rs

1use std::hash::Hash;
2
3use serde::{Deserialize, Serialize};
4
5#[cfg(feature = "typescript")]
6use ts_rs::TS;
7
8use crate::{id::TagId, PlatformId, PostId};
9
10/// A label that can be applied to posts
11///
12/// # Safety
13/// - Name must not be empty
14/// - Name should be kebab-case
15/// - Name can be chained (e.g. "x:y:z")
16#[cfg_attr(feature = "typescript", derive(TS))]
17#[cfg_attr(feature = "typescript", ts(export))]
18#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
19pub struct Tag {
20    pub id: TagId,
21    pub name: String,
22    pub platform: Option<PlatformId>,
23}
24
25/// Association type that creates a many-to-many relationship between posts and tags
26#[cfg_attr(feature = "typescript", derive(TS))]
27#[cfg_attr(feature = "typescript", ts(export))]
28#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Hash)]
29pub struct PostTag {
30    pub post: PostId,
31    pub tag: TagId,
32}
33
34#[cfg(feature = "utils")]
35crate::utils::macros::as_table! {
36    Tag {
37        id: "id",
38        name: "name",
39        platform: "platform",
40    }
41
42    PostTag {
43        post: "post",
44        tag: "tag",
45    }
46}