]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
Use URL type in most outstanding struct fields (#1468)
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::{
2   schema::{community, community_follower, community_moderator, community_user_ban},
3   DbUrl,
4 };
5 use serde::Serialize;
6
7 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
8 #[table_name = "community"]
9 pub struct Community {
10   pub id: i32,
11   pub name: String,
12   pub title: String,
13   pub description: Option<String>,
14   pub creator_id: i32,
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   pub private_key: Option<String>,
23   pub public_key: Option<String>,
24   pub last_refreshed_at: chrono::NaiveDateTime,
25   pub icon: Option<DbUrl>,
26   pub banner: Option<DbUrl>,
27   pub followers_url: DbUrl,
28   pub inbox_url: DbUrl,
29   pub shared_inbox_url: Option<DbUrl>,
30 }
31
32 /// A safe representation of community, without the sensitive info
33 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
34 #[table_name = "community"]
35 pub struct CommunitySafe {
36   pub id: i32,
37   pub name: String,
38   pub title: String,
39   pub description: Option<String>,
40   pub creator_id: i32,
41   pub removed: bool,
42   pub published: chrono::NaiveDateTime,
43   pub updated: Option<chrono::NaiveDateTime>,
44   pub deleted: bool,
45   pub nsfw: bool,
46   pub actor_id: DbUrl,
47   pub local: bool,
48   pub icon: Option<DbUrl>,
49   pub banner: Option<DbUrl>,
50 }
51
52 #[derive(Insertable, AsChangeset, Debug)]
53 #[table_name = "community"]
54 pub struct CommunityForm {
55   pub name: String,
56   pub title: String,
57   pub description: Option<String>,
58   pub creator_id: i32,
59   pub removed: Option<bool>,
60   pub published: Option<chrono::NaiveDateTime>,
61   pub updated: Option<chrono::NaiveDateTime>,
62   pub deleted: Option<bool>,
63   pub nsfw: bool,
64   pub actor_id: Option<DbUrl>,
65   pub local: bool,
66   pub private_key: Option<String>,
67   pub public_key: Option<String>,
68   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
69   pub icon: Option<Option<DbUrl>>,
70   pub banner: Option<Option<DbUrl>>,
71   pub followers_url: Option<DbUrl>,
72   pub inbox_url: Option<DbUrl>,
73   pub shared_inbox_url: Option<Option<DbUrl>>,
74 }
75
76 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
77 #[belongs_to(Community)]
78 #[table_name = "community_moderator"]
79 pub struct CommunityModerator {
80   pub id: i32,
81   pub community_id: i32,
82   pub user_id: i32,
83   pub published: chrono::NaiveDateTime,
84 }
85
86 #[derive(Insertable, AsChangeset, Clone)]
87 #[table_name = "community_moderator"]
88 pub struct CommunityModeratorForm {
89   pub community_id: i32,
90   pub user_id: i32,
91 }
92
93 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
94 #[belongs_to(Community)]
95 #[table_name = "community_user_ban"]
96 pub struct CommunityUserBan {
97   pub id: i32,
98   pub community_id: i32,
99   pub user_id: i32,
100   pub published: chrono::NaiveDateTime,
101 }
102
103 #[derive(Insertable, AsChangeset, Clone)]
104 #[table_name = "community_user_ban"]
105 pub struct CommunityUserBanForm {
106   pub community_id: i32,
107   pub user_id: i32,
108 }
109
110 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
111 #[belongs_to(Community)]
112 #[table_name = "community_follower"]
113 pub struct CommunityFollower {
114   pub id: i32,
115   pub community_id: i32,
116   pub user_id: i32,
117   pub published: chrono::NaiveDateTime,
118   pub pending: Option<bool>,
119 }
120
121 #[derive(Insertable, AsChangeset, Clone)]
122 #[table_name = "community_follower"]
123 pub struct CommunityFollowerForm {
124   pub community_id: i32,
125   pub user_id: i32,
126   pub pending: bool,
127 }