]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Fall back to String for Comment::path when not using the full feature (#2941)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 #[cfg(feature = "full")]
2 use crate::newtypes::LtreeDef;
3 use crate::newtypes::{CommentId, DbUrl, LanguageId, PersonId, PostId};
4 #[cfg(feature = "full")]
5 use crate::schema::{comment, comment_like, comment_saved};
6 #[cfg(feature = "full")]
7 use diesel_ltree::Ltree;
8 use serde::{Deserialize, Serialize};
9 use serde_with::skip_serializing_none;
10 #[cfg(feature = "full")]
11 use ts_rs::TS;
12 use typed_builder::TypedBuilder;
13
14 #[skip_serializing_none]
15 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
16 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
17 #[cfg_attr(feature = "full", ts(export))]
18 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
19 #[cfg_attr(feature = "full", diesel(table_name = comment))]
20 /// A comment.
21 pub struct Comment {
22   pub id: CommentId,
23   pub creator_id: PersonId,
24   pub post_id: PostId,
25   pub content: String,
26   /// Whether the comment has been removed.
27   pub removed: bool,
28   pub published: chrono::NaiveDateTime,
29   pub updated: Option<chrono::NaiveDateTime>,
30   /// Whether the comment has been deleted by its creator.
31   pub deleted: bool,
32   /// The federated activity id / ap_id.
33   pub ap_id: DbUrl,
34   /// Whether the comment is local.
35   pub local: bool,
36   #[cfg(feature = "full")]
37   #[cfg_attr(feature = "full", serde(with = "LtreeDef"))]
38   #[cfg_attr(feature = "full", ts(type = "string"))]
39   /// The path / tree location of a comment, separated by dots, ending with the comment's id. Ex: 0.24.27
40   pub path: Ltree,
41   #[cfg(not(feature = "full"))]
42   pub path: String,
43   /// Whether the comment has been distinguished(speaking officially) by a mod.
44   pub distinguished: bool,
45   pub language_id: LanguageId,
46 }
47
48 #[derive(Debug, Clone, TypedBuilder)]
49 #[builder(field_defaults(default))]
50 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
51 #[cfg_attr(feature = "full", diesel(table_name = comment))]
52 pub struct CommentInsertForm {
53   #[builder(!default)]
54   pub creator_id: PersonId,
55   #[builder(!default)]
56   pub post_id: PostId,
57   #[builder(!default)]
58   pub content: String,
59   pub removed: Option<bool>,
60   pub published: Option<chrono::NaiveDateTime>,
61   pub updated: Option<chrono::NaiveDateTime>,
62   pub deleted: Option<bool>,
63   pub ap_id: Option<DbUrl>,
64   pub local: Option<bool>,
65   pub distinguished: Option<bool>,
66   pub language_id: Option<LanguageId>,
67 }
68
69 #[derive(Debug, Clone, TypedBuilder)]
70 #[builder(field_defaults(default))]
71 #[cfg_attr(feature = "full", derive(AsChangeset))]
72 #[cfg_attr(feature = "full", diesel(table_name = comment))]
73 pub struct CommentUpdateForm {
74   pub content: Option<String>,
75   pub removed: Option<bool>,
76   // Don't use a default naive_now here, because the create function does a lot of comment updates
77   pub updated: Option<Option<chrono::NaiveDateTime>>,
78   pub deleted: Option<bool>,
79   pub ap_id: Option<DbUrl>,
80   pub local: Option<bool>,
81   pub distinguished: Option<bool>,
82   pub language_id: Option<LanguageId>,
83 }
84
85 #[derive(PartialEq, Eq, Debug, Clone)]
86 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
87 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
88 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
89 pub struct CommentLike {
90   pub id: i32,
91   pub person_id: PersonId,
92   pub comment_id: CommentId,
93   pub post_id: PostId, // TODO this is redundant
94   pub score: i16,
95   pub published: chrono::NaiveDateTime,
96 }
97
98 #[derive(Clone)]
99 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
100 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
101 pub struct CommentLikeForm {
102   pub person_id: PersonId,
103   pub comment_id: CommentId,
104   pub post_id: PostId, // TODO this is redundant
105   pub score: i16,
106 }
107
108 #[derive(PartialEq, Eq, Debug)]
109 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
110 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
111 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
112 pub struct CommentSaved {
113   pub id: i32,
114   pub comment_id: CommentId,
115   pub person_id: PersonId,
116   pub published: chrono::NaiveDateTime,
117 }
118
119 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
120 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
121 pub struct CommentSavedForm {
122   pub comment_id: CommentId,
123   pub person_id: PersonId,
124 }