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 typed_builder::TypedBuilder;
11 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
12 #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
13 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
14 #[cfg_attr(feature = "full", diesel(table_name = comment))]
17 pub creator_id: PersonId,
21 pub published: chrono::NaiveDateTime,
22 pub updated: Option<chrono::NaiveDateTime>,
26 #[cfg(feature = "full")]
27 #[serde(with = "LtreeDef")]
29 pub distinguished: bool,
30 pub language_id: LanguageId,
33 #[derive(Debug, Clone, TypedBuilder)]
34 #[builder(field_defaults(default))]
35 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
36 #[cfg_attr(feature = "full", diesel(table_name = comment))]
37 pub struct CommentInsertForm {
39 pub creator_id: PersonId,
44 pub removed: Option<bool>,
45 pub published: Option<chrono::NaiveDateTime>,
46 pub updated: Option<chrono::NaiveDateTime>,
47 pub deleted: Option<bool>,
48 pub ap_id: Option<DbUrl>,
49 pub local: Option<bool>,
50 pub distinguished: Option<bool>,
51 pub language_id: Option<LanguageId>,
54 #[derive(Debug, Clone, TypedBuilder)]
55 #[builder(field_defaults(default))]
56 #[cfg_attr(feature = "full", derive(AsChangeset))]
57 #[cfg_attr(feature = "full", diesel(table_name = comment))]
58 pub struct CommentUpdateForm {
59 pub content: Option<String>,
60 pub removed: Option<bool>,
61 // Don't use a default naive_now here, because the create function does a lot of comment updates
62 pub updated: Option<Option<chrono::NaiveDateTime>>,
63 pub deleted: Option<bool>,
64 pub ap_id: Option<DbUrl>,
65 pub local: Option<bool>,
66 pub distinguished: Option<bool>,
67 pub language_id: Option<LanguageId>,
70 #[derive(PartialEq, Eq, Debug, Clone)]
71 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
72 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
73 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
74 pub struct CommentLike {
76 pub person_id: PersonId,
77 pub comment_id: CommentId,
78 pub post_id: PostId, // TODO this is redundant
80 pub published: chrono::NaiveDateTime,
84 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
85 #[cfg_attr(feature = "full", diesel(table_name = comment_like))]
86 pub struct CommentLikeForm {
87 pub person_id: PersonId,
88 pub comment_id: CommentId,
89 pub post_id: PostId, // TODO this is redundant
93 #[derive(PartialEq, Eq, Debug)]
94 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
95 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
96 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
97 pub struct CommentSaved {
99 pub comment_id: CommentId,
100 pub person_id: PersonId,
101 pub published: chrono::NaiveDateTime,
104 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
105 #[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
106 pub struct CommentSavedForm {
107 pub comment_id: CommentId,
108 pub person_id: PersonId,