]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/person.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / db_schema / src / source / person.rs
1 use crate::newtypes::{DbUrl, InstanceId, PersonId};
2 use serde::{Deserialize, Serialize};
3 use typed_builder::TypedBuilder;
4
5 #[cfg(feature = "full")]
6 use crate::schema::person;
7
8 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
9 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
10 #[cfg_attr(feature = "full", diesel(table_name = person))]
11 pub struct Person {
12   pub id: PersonId,
13   pub name: String,
14   pub display_name: Option<String>,
15   pub avatar: Option<DbUrl>,
16   pub banned: bool,
17   pub published: chrono::NaiveDateTime,
18   pub updated: Option<chrono::NaiveDateTime>,
19   pub actor_id: DbUrl,
20   pub bio: Option<String>,
21   pub local: bool,
22   pub private_key: Option<String>,
23   pub public_key: String,
24   pub last_refreshed_at: chrono::NaiveDateTime,
25   pub banner: Option<DbUrl>,
26   pub deleted: bool,
27   pub inbox_url: DbUrl,
28   pub shared_inbox_url: Option<DbUrl>,
29   pub matrix_user_id: Option<String>,
30   pub admin: bool,
31   pub bot_account: bool,
32   pub ban_expires: Option<chrono::NaiveDateTime>,
33   pub instance_id: InstanceId,
34 }
35
36 /// A safe representation of person, without the sensitive info
37 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
38 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
39 #[cfg_attr(feature = "full", diesel(table_name = person))]
40 pub struct PersonSafe {
41   pub id: PersonId,
42   pub name: String,
43   pub display_name: Option<String>,
44   pub avatar: Option<DbUrl>,
45   pub banned: bool,
46   pub published: chrono::NaiveDateTime,
47   pub updated: Option<chrono::NaiveDateTime>,
48   pub actor_id: DbUrl,
49   pub bio: Option<String>,
50   pub local: bool,
51   pub banner: Option<DbUrl>,
52   pub deleted: bool,
53   pub inbox_url: DbUrl,
54   pub shared_inbox_url: Option<DbUrl>,
55   pub matrix_user_id: Option<String>,
56   pub admin: bool,
57   pub bot_account: bool,
58   pub ban_expires: Option<chrono::NaiveDateTime>,
59   pub instance_id: InstanceId,
60 }
61
62 #[derive(Clone, TypedBuilder)]
63 #[builder(field_defaults(default))]
64 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
65 #[cfg_attr(feature = "full", diesel(table_name = person))]
66 pub struct PersonInsertForm {
67   #[builder(!default)]
68   pub name: String,
69   #[builder(!default)]
70   pub public_key: String,
71   #[builder(!default)]
72   pub instance_id: InstanceId,
73   pub display_name: Option<String>,
74   pub avatar: Option<DbUrl>,
75   pub banned: Option<bool>,
76   pub published: Option<chrono::NaiveDateTime>,
77   pub updated: Option<chrono::NaiveDateTime>,
78   pub actor_id: Option<DbUrl>,
79   pub bio: Option<String>,
80   pub local: Option<bool>,
81   pub private_key: Option<String>,
82   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
83   pub banner: Option<DbUrl>,
84   pub deleted: Option<bool>,
85   pub inbox_url: Option<DbUrl>,
86   pub shared_inbox_url: Option<DbUrl>,
87   pub matrix_user_id: Option<String>,
88   pub admin: Option<bool>,
89   pub bot_account: Option<bool>,
90   pub ban_expires: Option<chrono::NaiveDateTime>,
91 }
92
93 #[derive(Clone, TypedBuilder)]
94 #[cfg_attr(feature = "full", derive(AsChangeset))]
95 #[cfg_attr(feature = "full", diesel(table_name = person))]
96 #[builder(field_defaults(default))]
97 pub struct PersonUpdateForm {
98   pub display_name: Option<Option<String>>,
99   pub avatar: Option<Option<DbUrl>>,
100   pub banned: Option<bool>,
101   pub updated: Option<Option<chrono::NaiveDateTime>>,
102   pub actor_id: Option<DbUrl>,
103   pub bio: Option<Option<String>>,
104   pub local: Option<bool>,
105   pub public_key: Option<String>,
106   pub private_key: Option<Option<String>>,
107   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
108   pub banner: Option<Option<DbUrl>>,
109   pub deleted: Option<bool>,
110   pub inbox_url: Option<DbUrl>,
111   pub shared_inbox_url: Option<Option<DbUrl>>,
112   pub matrix_user_id: Option<Option<String>>,
113   pub admin: Option<bool>,
114   pub bot_account: Option<bool>,
115   pub ban_expires: Option<Option<chrono::NaiveDateTime>>,
116 }