]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
Adding diesel enums for SortType and ListingType (#2808)
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId};
2 #[cfg(feature = "full")]
3 use crate::schema::{community, community_follower, community_moderator, community_person_ban};
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 = community))]
10 pub struct Community {
11   pub id: CommunityId,
12   pub name: String,
13   pub title: String,
14   pub description: Option<String>,
15   pub removed: bool,
16   pub published: chrono::NaiveDateTime,
17   pub updated: Option<chrono::NaiveDateTime>,
18   pub deleted: bool,
19   pub nsfw: bool,
20   pub actor_id: DbUrl,
21   pub local: bool,
22   #[serde(skip)]
23   pub private_key: Option<String>,
24   #[serde(skip)]
25   pub public_key: String,
26   #[serde(skip)]
27   pub last_refreshed_at: chrono::NaiveDateTime,
28   pub icon: Option<DbUrl>,
29   pub banner: Option<DbUrl>,
30   #[serde(skip_serializing)]
31   pub followers_url: DbUrl,
32   #[serde(skip_serializing)]
33   pub inbox_url: DbUrl,
34   #[serde(skip)]
35   pub shared_inbox_url: Option<DbUrl>,
36   pub hidden: bool,
37   pub posting_restricted_to_mods: bool,
38   pub instance_id: InstanceId,
39   /// Url where moderators collection is served over Activitypub
40   #[serde(skip)]
41   pub moderators_url: Option<DbUrl>,
42   /// Url where featured posts collection is served over Activitypub
43   #[serde(skip)]
44   pub featured_url: Option<DbUrl>,
45 }
46
47 #[derive(Debug, Clone, TypedBuilder)]
48 #[builder(field_defaults(default))]
49 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
50 #[cfg_attr(feature = "full", diesel(table_name = community))]
51 pub struct CommunityInsertForm {
52   #[builder(!default)]
53   pub name: String,
54   #[builder(!default)]
55   pub title: String,
56   pub description: Option<String>,
57   pub removed: Option<bool>,
58   pub published: Option<chrono::NaiveDateTime>,
59   pub updated: Option<chrono::NaiveDateTime>,
60   pub deleted: Option<bool>,
61   pub nsfw: Option<bool>,
62   pub actor_id: Option<DbUrl>,
63   pub local: Option<bool>,
64   pub private_key: Option<String>,
65   pub public_key: String,
66   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
67   pub icon: Option<DbUrl>,
68   pub banner: Option<DbUrl>,
69   pub followers_url: Option<DbUrl>,
70   pub inbox_url: Option<DbUrl>,
71   pub shared_inbox_url: Option<DbUrl>,
72   pub moderators_url: Option<DbUrl>,
73   pub featured_url: Option<DbUrl>,
74   pub hidden: Option<bool>,
75   pub posting_restricted_to_mods: Option<bool>,
76   #[builder(!default)]
77   pub instance_id: InstanceId,
78 }
79
80 #[derive(Debug, Clone, TypedBuilder)]
81 #[builder(field_defaults(default))]
82 #[cfg_attr(feature = "full", derive(AsChangeset))]
83 #[cfg_attr(feature = "full", diesel(table_name = community))]
84 pub struct CommunityUpdateForm {
85   pub title: Option<String>,
86   pub description: Option<Option<String>>,
87   pub removed: Option<bool>,
88   pub published: Option<chrono::NaiveDateTime>,
89   pub updated: Option<Option<chrono::NaiveDateTime>>,
90   pub deleted: Option<bool>,
91   pub nsfw: Option<bool>,
92   pub actor_id: Option<DbUrl>,
93   pub local: Option<bool>,
94   pub public_key: Option<String>,
95   pub private_key: Option<Option<String>>,
96   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
97   pub icon: Option<Option<DbUrl>>,
98   pub banner: Option<Option<DbUrl>>,
99   pub followers_url: Option<DbUrl>,
100   pub inbox_url: Option<DbUrl>,
101   pub shared_inbox_url: Option<Option<DbUrl>>,
102   pub moderators_url: Option<DbUrl>,
103   pub featured_url: Option<DbUrl>,
104   pub hidden: Option<bool>,
105   pub posting_restricted_to_mods: Option<bool>,
106 }
107
108 #[derive(PartialEq, Eq, Debug)]
109 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
110 #[cfg_attr(
111   feature = "full",
112   diesel(belongs_to(crate::source::community::Community))
113 )]
114 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
115 pub struct CommunityModerator {
116   pub id: i32,
117   pub community_id: CommunityId,
118   pub person_id: PersonId,
119   pub published: chrono::NaiveDateTime,
120 }
121
122 #[derive(Clone)]
123 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
124 #[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
125 pub struct CommunityModeratorForm {
126   pub community_id: CommunityId,
127   pub person_id: PersonId,
128 }
129
130 #[derive(PartialEq, Eq, Debug)]
131 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
132 #[cfg_attr(
133   feature = "full",
134   diesel(belongs_to(crate::source::community::Community))
135 )]
136 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
137 pub struct CommunityPersonBan {
138   pub id: i32,
139   pub community_id: CommunityId,
140   pub person_id: PersonId,
141   pub published: chrono::NaiveDateTime,
142   pub expires: Option<chrono::NaiveDateTime>,
143 }
144
145 #[derive(Clone)]
146 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
147 #[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
148 pub struct CommunityPersonBanForm {
149   pub community_id: CommunityId,
150   pub person_id: PersonId,
151   pub expires: Option<Option<chrono::NaiveDateTime>>,
152 }
153
154 #[derive(PartialEq, Eq, Debug)]
155 #[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
156 #[cfg_attr(
157   feature = "full",
158   diesel(belongs_to(crate::source::community::Community))
159 )]
160 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
161 pub struct CommunityFollower {
162   pub id: i32,
163   pub community_id: CommunityId,
164   pub person_id: PersonId,
165   pub published: chrono::NaiveDateTime,
166   pub pending: bool,
167 }
168
169 #[derive(Clone)]
170 #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
171 #[cfg_attr(feature = "full", diesel(table_name = community_follower))]
172 pub struct CommunityFollowerForm {
173   pub community_id: CommunityId,
174   pub person_id: PersonId,
175   pub pending: bool,
176 }