]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 use crate::newtypes::{CommentId, DbUrl, LanguageId, LtreeDef, PersonId, PostId};
2 use diesel_ltree::Ltree;
3 use serde::{Deserialize, Serialize};
4 use typed_builder::TypedBuilder;
5
6 #[cfg(feature = "full")]
7 use crate::schema::{comment, comment_like, comment_saved};
8
9 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
10 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
11 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
12 #[cfg_attr(feature = "full", diesel(table_name = comment))]
13 pub struct Comment {
14   pub id: CommentId,
15   pub creator_id: PersonId,
16   pub post_id: PostId,
17   pub content: String,
18   pub removed: bool,
19   pub published: chrono::NaiveDateTime,
20   pub updated: Option<chrono::NaiveDateTime>,
21   pub deleted: bool,
22   pub ap_id: DbUrl,
23   pub local: bool,
24   #[serde(with = "LtreeDef")]
25   pub path: Ltree,
26   pub distinguished: bool,
27   pub language_id: LanguageId,
28 }
29
30 #[derive(Debug, Clone, TypedBuilder)]
31 #[builder(field_defaults(default))]
32 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
33 #[cfg_attr(feature = "full", diesel(table_name = comment))]
34 pub struct CommentInsertForm {
35   #[builder(!default)]
36   pub creator_id: PersonId,
37   #[builder(!default)]
38   pub post_id: PostId,
39   #[builder(!default)]
40   pub content: String,
41   pub removed: Option<bool>,
42   pub published: Option<chrono::NaiveDateTime>,
43   pub updated: Option<chrono::NaiveDateTime>,
44   pub deleted: Option<bool>,
45   pub ap_id: Option<DbUrl>,
46   pub local: Option<bool>,
47   pub distinguished: Option<bool>,
48   pub language_id: Option<LanguageId>,
49 }
50
51 #[derive(Debug, Clone, TypedBuilder)]
52 #[builder(field_defaults(default))]
53 #[cfg_attr(feature = "full", derive(AsChangeset))]
54 #[cfg_attr(feature = "full", diesel(table_name = comment))]
55 pub struct CommentUpdateForm {
56   pub content: Option<String>,
57   pub removed: Option<bool>,
58   // Don't use a default naive_now here, because the create function does a lot of comment updates
59   pub updated: Option<Option<chrono::NaiveDateTime>>,
60   pub deleted: Option<bool>,
61   pub ap_id: Option<DbUrl>,
62   pub local: Option<bool>,
63   pub distinguished: Option<bool>,
64   pub language_id: Option<LanguageId>,
65 }
66
67 #[derive(PartialEq, Eq, Debug, Clone)]
68 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
69 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
70 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
71 pub struct CommentLike {
72   pub id: i32,
73   pub person_id: PersonId,
74   pub comment_id: CommentId,
75   pub post_id: PostId, // TODO this is redundant
76   pub score: i16,
77   pub published: chrono::NaiveDateTime,
78 }
79
80 #[derive(Clone)]
81 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
82 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
83 pub struct CommentLikeForm {
84   pub person_id: PersonId,
85   pub comment_id: CommentId,
86   pub post_id: PostId, // TODO this is redundant
87   pub score: i16,
88 }
89
90 #[derive(PartialEq, Eq, Debug)]
91 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
92 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
93 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
94 pub struct CommentSaved {
95   pub id: i32,
96   pub comment_id: CommentId,
97   pub person_id: PersonId,
98   pub published: chrono::NaiveDateTime,
99 }
100
101 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
102 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
103 pub struct CommentSavedForm {
104   pub comment_id: CommentId,
105   pub person_id: PersonId,
106 }