]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/comment.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / db_schema / src / source / comment.rs
1 use crate::newtypes::{CommentId, DbUrl, 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, Debug, Serialize, Deserialize)]
9 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
10 #[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
11 #[cfg_attr(feature = "full", 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 }
26
27 #[derive(Clone, Default)]
28 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
29 #[cfg_attr(feature = "full", table_name = "comment")]
30 pub struct CommentForm {
31   pub creator_id: PersonId,
32   pub post_id: PostId,
33   pub content: String,
34   pub removed: Option<bool>,
35   pub published: Option<chrono::NaiveDateTime>,
36   pub updated: Option<chrono::NaiveDateTime>,
37   pub deleted: Option<bool>,
38   pub ap_id: Option<DbUrl>,
39   pub local: Option<bool>,
40 }
41
42 #[derive(PartialEq, Debug, Clone)]
43 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
44 #[cfg_attr(feature = "full", belongs_to(Comment))]
45 #[cfg_attr(feature = "full", table_name = "comment_like")]
46 pub struct CommentLike {
47   pub id: i32,
48   pub person_id: PersonId,
49   pub comment_id: CommentId,
50   pub post_id: PostId, // TODO this is redundant
51   pub score: i16,
52   pub published: chrono::NaiveDateTime,
53 }
54
55 #[derive(Clone)]
56 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
57 #[cfg_attr(feature = "full", table_name = "comment_like")]
58 pub struct CommentLikeForm {
59   pub person_id: PersonId,
60   pub comment_id: CommentId,
61   pub post_id: PostId, // TODO this is redundant
62   pub score: i16,
63 }
64
65 #[derive(PartialEq, Debug)]
66 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
67 #[cfg_attr(feature = "full", belongs_to(Comment))]
68 #[cfg_attr(feature = "full", table_name = "comment_saved")]
69 pub struct CommentSaved {
70   pub id: i32,
71   pub comment_id: CommentId,
72   pub person_id: PersonId,
73   pub published: chrono::NaiveDateTime,
74 }
75
76 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
77 #[cfg_attr(feature = "full", table_name = "comment_saved")]
78 pub struct CommentSavedForm {
79   pub comment_id: CommentId,
80   pub person_id: PersonId,
81 }