]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
Add cargo feature for building lemmy_api_common with mininum deps (#2243)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 use crate::newtypes::{CommentId, DbUrl, PersonId, PostId};
2 use serde::{Deserialize, Serialize};
3
4 #[cfg(feature = "full")]
5 use crate::schema::{comment, comment_alias_1, comment_like, comment_saved};
6
7 // WITH RECURSIVE MyTree AS (
8 //     SELECT * FROM comment WHERE parent_id IS NULL
9 //     UNION ALL
10 //     SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
11 // )
12 // SELECT * FROM MyTree;
13
14 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
15 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
16 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
17 #[cfg_attr(feature = "full", table_name = "comment")]
18 pub struct Comment {
19   pub id: CommentId,
20   pub creator_id: PersonId,
21   pub post_id: PostId,
22   pub parent_id: Option<CommentId>,
23   pub content: String,
24   pub removed: bool,
25   pub read: bool, // Whether the recipient has read the comment or not
26   pub published: chrono::NaiveDateTime,
27   pub updated: Option<chrono::NaiveDateTime>,
28   pub deleted: bool,
29   pub ap_id: DbUrl,
30   pub local: bool,
31 }
32
33 #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
34 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
35 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
36 #[cfg_attr(feature = "full", table_name = "comment_alias_1")]
37 pub struct CommentAlias1 {
38   pub id: CommentId,
39   pub creator_id: PersonId,
40   pub post_id: PostId,
41   pub parent_id: Option<CommentId>,
42   pub content: String,
43   pub removed: bool,
44   pub read: bool, // Whether the recipient has read the comment or not
45   pub published: chrono::NaiveDateTime,
46   pub updated: Option<chrono::NaiveDateTime>,
47   pub deleted: bool,
48   pub ap_id: DbUrl,
49   pub local: bool,
50 }
51
52 #[derive(Clone, Default)]
53 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
54 #[cfg_attr(feature = "full", table_name = "comment")]
55 pub struct CommentForm {
56   pub creator_id: PersonId,
57   pub post_id: PostId,
58   pub content: String,
59   pub parent_id: Option<CommentId>,
60   pub removed: Option<bool>,
61   pub read: Option<bool>,
62   pub published: Option<chrono::NaiveDateTime>,
63   pub updated: Option<chrono::NaiveDateTime>,
64   pub deleted: Option<bool>,
65   pub ap_id: Option<DbUrl>,
66   pub local: Option<bool>,
67 }
68
69 #[derive(PartialEq, Debug, Clone)]
70 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
71 #[cfg_attr(feature = "full", belongs_to(Comment))]
72 #[cfg_attr(feature = "full", table_name = "comment_like")]
73 pub struct CommentLike {
74   pub id: i32,
75   pub person_id: PersonId,
76   pub comment_id: CommentId,
77   pub post_id: PostId, // TODO this is redundant
78   pub score: i16,
79   pub published: chrono::NaiveDateTime,
80 }
81
82 #[derive(Clone)]
83 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
84 #[cfg_attr(feature = "full", table_name = "comment_like")]
85 pub struct CommentLikeForm {
86   pub person_id: PersonId,
87   pub comment_id: CommentId,
88   pub post_id: PostId, // TODO this is redundant
89   pub score: i16,
90 }
91
92 #[derive(PartialEq, Debug)]
93 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
94 #[cfg_attr(feature = "full", belongs_to(Comment))]
95 #[cfg_attr(feature = "full", table_name = "comment_saved")]
96 pub struct CommentSaved {
97   pub id: i32,
98   pub comment_id: CommentId,
99   pub person_id: PersonId,
100   pub published: chrono::NaiveDateTime,
101 }
102
103 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
104 #[cfg_attr(feature = "full", table_name = "comment_saved")]
105 pub struct CommentSavedForm {
106   pub comment_id: CommentId,
107   pub person_id: PersonId,
108 }