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