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")]
12 use typed_builder::TypedBuilder;
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))]
22 pub creator_id: PersonId,
26 pub published: chrono::NaiveDateTime,
27 pub updated: Option<chrono::NaiveDateTime>,
31 #[cfg(feature = "full")]
32 #[cfg_attr(feature = "full", serde(with = "LtreeDef"))]
33 #[cfg_attr(feature = "full", ts(type = "string"))]
35 pub distinguished: bool,
36 pub language_id: LanguageId,
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 {
45 pub creator_id: PersonId,
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>,
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>,
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 {
82 pub person_id: PersonId,
83 pub comment_id: CommentId,
84 pub post_id: PostId, // TODO this is redundant
86 pub published: chrono::NaiveDateTime,
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
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 {
105 pub comment_id: CommentId,
106 pub person_id: PersonId,
107 pub published: chrono::NaiveDateTime,
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,