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