8 description -> Nullable<Text>,
12 published -> Timestamp,
13 updated -> Nullable<Timestamp>,
16 creator_name -> Varchar,
17 category_name -> Varchar,
18 number_of_subscribers -> BigInt,
19 number_of_posts -> BigInt,
20 number_of_comments -> BigInt,
22 user_id -> Nullable<Int4>,
23 subscribed -> Nullable<Bool>,
28 community_moderator_view (id) {
32 published -> Timestamp,
34 community_name -> Varchar,
39 community_follower_view (id) {
43 published -> Timestamp,
45 community_name -> Varchar,
50 community_user_ban_view (id) {
54 published -> Timestamp,
56 community_name -> Varchar,
64 description -> Nullable<Text>,
66 published -> Timestamp,
67 updated -> Nullable<Timestamp>,
68 creator_name -> Varchar,
69 number_of_users -> BigInt,
70 number_of_posts -> BigInt,
71 number_of_comments -> BigInt,
72 number_of_communities -> BigInt,
77 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
79 #[table_name = "community_view"]
80 pub struct CommunityView {
84 pub description: Option<String>,
88 pub published: chrono::NaiveDateTime,
89 pub updated: Option<chrono::NaiveDateTime>,
92 pub creator_name: String,
93 pub category_name: String,
94 pub number_of_subscribers: i64,
95 pub number_of_posts: i64,
96 pub number_of_comments: i64,
98 pub user_id: Option<i32>,
99 pub subscribed: Option<bool>,
105 from_community_id: i32,
106 from_user_id: Option<i32>,
107 ) -> Result<Self, Error> {
108 use super::community_view::community_view::dsl::*;
110 let mut query = community_view.into_boxed();
112 query = query.filter(id.eq(from_community_id));
114 // The view lets you pass a null user_id, if you're not logged in
115 if let Some(from_user_id) = from_user_id {
116 query = query.filter(user_id.eq(from_user_id));
118 query = query.filter(user_id.is_null());
121 query.first::<Self>(conn)
127 from_user_id: Option<i32>,
129 search_term: Option<String>,
132 ) -> Result<Vec<Self>, Error> {
133 use super::community_view::community_view::dsl::*;
134 let mut query = community_view.into_boxed();
136 let (limit, offset) = limit_and_offset(page, limit);
138 if let Some(search_term) = search_term {
139 query = query.filter(name.ilike(fuzzy_search(&search_term)));
142 // The view lets you pass a null user_id, if you're not logged in
146 .order_by(hot_rank.desc())
147 .then_order_by(number_of_subscribers.desc())
148 .filter(user_id.is_null())
150 SortType::New => query = query.order_by(published.desc()).filter(user_id.is_null()),
151 SortType::TopAll => match from_user_id {
152 Some(from_user_id) => {
154 .filter(user_id.eq(from_user_id))
155 .order_by((subscribed.asc(), number_of_subscribers.desc()))
159 .order_by(number_of_subscribers.desc())
160 .filter(user_id.is_null())
167 query = query.filter(nsfw.eq(false));
173 .filter(removed.eq(false))
174 .filter(deleted.eq(false))
180 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
182 #[table_name = "community_moderator_view"]
183 pub struct CommunityModeratorView {
185 pub community_id: i32,
187 pub published: chrono::NaiveDateTime,
188 pub user_name: String,
189 pub community_name: String,
192 impl CommunityModeratorView {
193 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
194 use super::community_view::community_moderator_view::dsl::*;
195 community_moderator_view
196 .filter(community_id.eq(from_community_id))
200 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
201 use super::community_view::community_moderator_view::dsl::*;
202 community_moderator_view
203 .filter(user_id.eq(from_user_id))
209 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
211 #[table_name = "community_follower_view"]
212 pub struct CommunityFollowerView {
214 pub community_id: i32,
216 pub published: chrono::NaiveDateTime,
217 pub user_name: String,
218 pub community_name: String,
221 impl CommunityFollowerView {
222 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
223 use super::community_view::community_follower_view::dsl::*;
224 community_follower_view
225 .filter(community_id.eq(from_community_id))
229 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
230 use super::community_view::community_follower_view::dsl::*;
231 community_follower_view
232 .filter(user_id.eq(from_user_id))
238 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
240 #[table_name = "community_user_ban_view"]
241 pub struct CommunityUserBanView {
243 pub community_id: i32,
245 pub published: chrono::NaiveDateTime,
246 pub user_name: String,
247 pub community_name: String,
250 impl CommunityUserBanView {
251 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
252 use super::community_view::community_user_ban_view::dsl::*;
253 community_user_ban_view
254 .filter(community_id.eq(from_community_id))
258 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
259 use super::community_view::community_user_ban_view::dsl::*;
260 community_user_ban_view
261 .filter(user_id.eq(from_user_id))
268 from_community_id: i32,
269 ) -> Result<Self, Error> {
270 use super::community_view::community_user_ban_view::dsl::*;
271 community_user_ban_view
272 .filter(user_id.eq(from_user_id))
273 .filter(community_id.eq(from_community_id))
279 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
281 #[table_name = "site_view"]
282 pub struct SiteView {
285 pub description: Option<String>,
287 pub published: chrono::NaiveDateTime,
288 pub updated: Option<chrono::NaiveDateTime>,
289 pub creator_name: String,
290 pub number_of_users: i64,
291 pub number_of_posts: i64,
292 pub number_of_comments: i64,
293 pub number_of_communities: i64,
297 pub fn read(conn: &PgConnection) -> Result<Self, Error> {
298 use super::community_view::site_view::dsl::*;
299 site_view.first::<Self>(conn)