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