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