]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Diesel 2.0.0 upgrade (#2452)
[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
5 #[cfg(feature = "full")]
6 use crate::schema::{comment, comment_like, comment_saved};
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(Clone, Default)]
30 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
31 #[cfg_attr(feature = "full", diesel(table_name = comment))]
32 pub struct CommentForm {
33   pub creator_id: PersonId,
34   pub post_id: PostId,
35   pub content: String,
36   pub removed: Option<bool>,
37   pub published: Option<chrono::NaiveDateTime>,
38   pub updated: Option<chrono::NaiveDateTime>,
39   pub deleted: Option<bool>,
40   pub ap_id: Option<DbUrl>,
41   pub local: Option<bool>,
42   pub distinguished: Option<bool>,
43   pub language_id: Option<LanguageId>,
44 }
45
46 #[derive(PartialEq, Eq, Debug, Clone)]
47 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
48 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
49 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
50 pub struct CommentLike {
51   pub id: i32,
52   pub person_id: PersonId,
53   pub comment_id: CommentId,
54   pub post_id: PostId, // TODO this is redundant
55   pub score: i16,
56   pub published: chrono::NaiveDateTime,
57 }
58
59 #[derive(Clone)]
60 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
61 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
62 pub struct CommentLikeForm {
63   pub person_id: PersonId,
64   pub comment_id: CommentId,
65   pub post_id: PostId, // TODO this is redundant
66   pub score: i16,
67 }
68
69 #[derive(PartialEq, Eq, Debug)]
70 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
71 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
72 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
73 pub struct CommentSaved {
74   pub id: i32,
75   pub comment_id: CommentId,
76   pub person_id: PersonId,
77   pub published: chrono::NaiveDateTime,
78 }
79
80 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
81 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
82 pub struct CommentSavedForm {
83   pub comment_id: CommentId,
84   pub person_id: PersonId,
85 }