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