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,
76 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
77 #[table_name="community_view"]
78 pub struct CommunityView {
82 pub description: Option<String>,
86 pub published: chrono::NaiveDateTime,
87 pub updated: Option<chrono::NaiveDateTime>,
90 pub creator_name: String,
91 pub category_name: String,
92 pub number_of_subscribers: i64,
93 pub number_of_posts: i64,
94 pub number_of_comments: i64,
96 pub user_id: Option<i32>,
97 pub subscribed: Option<bool>,
101 pub fn read(conn: &PgConnection, from_community_id: i32, from_user_id: Option<i32>) -> Result<Self, Error> {
102 use super::community_view::community_view::dsl::*;
104 let mut query = community_view.into_boxed();
106 query = query.filter(id.eq(from_community_id));
108 // The view lets you pass a null user_id, if you're not logged in
109 if let Some(from_user_id) = from_user_id {
110 query = query.filter(user_id.eq(from_user_id));
112 query = query.filter(user_id.is_null());
115 query.first::<Self>(conn)
121 from_user_id: Option<i32>,
123 search_term: Option<String>,
126 ) -> Result<Vec<Self>, Error> {
127 use super::community_view::community_view::dsl::*;
128 let mut query = community_view.into_boxed();
130 let (limit, offset) = limit_and_offset(page, limit);
132 if let Some(search_term) = search_term {
133 query = query.filter(name.ilike(fuzzy_search(&search_term)));
136 // The view lets you pass a null user_id, if you're not logged in
138 SortType::Hot => query = query.order_by(hot_rank.desc())
139 .then_order_by(number_of_subscribers.desc())
140 .filter(user_id.is_null()),
141 SortType::New => query = query.order_by(published.desc()).filter(user_id.is_null()),
142 SortType::TopAll => {
144 Some(from_user_id) => query = query.filter(user_id.eq(from_user_id)).order_by((subscribed.asc(), number_of_subscribers.desc())),
145 None => query = query.order_by(number_of_subscribers.desc()).filter(user_id.is_null())
152 query = query.filter(nsfw.eq(false));
158 .filter(removed.eq(false))
159 .filter(deleted.eq(false))
165 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
166 #[table_name="community_moderator_view"]
167 pub struct CommunityModeratorView {
169 pub community_id: i32,
171 pub published: chrono::NaiveDateTime,
172 pub user_name : String,
173 pub community_name: String,
176 impl CommunityModeratorView {
177 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
178 use super::community_view::community_moderator_view::dsl::*;
179 community_moderator_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
182 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
183 use super::community_view::community_moderator_view::dsl::*;
184 community_moderator_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
188 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
189 #[table_name="community_follower_view"]
190 pub struct CommunityFollowerView {
192 pub community_id: i32,
194 pub published: chrono::NaiveDateTime,
195 pub user_name : String,
196 pub community_name: String,
199 impl CommunityFollowerView {
200 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
201 use super::community_view::community_follower_view::dsl::*;
202 community_follower_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
205 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
206 use super::community_view::community_follower_view::dsl::*;
207 community_follower_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
212 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
213 #[table_name="community_user_ban_view"]
214 pub struct CommunityUserBanView {
216 pub community_id: i32,
218 pub published: chrono::NaiveDateTime,
219 pub user_name : String,
220 pub community_name: String,
223 impl CommunityUserBanView {
224 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
225 use super::community_view::community_user_ban_view::dsl::*;
226 community_user_ban_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
229 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
230 use super::community_view::community_user_ban_view::dsl::*;
231 community_user_ban_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
234 pub fn get(conn: &PgConnection, from_user_id: i32, from_community_id: i32) -> Result<Self, Error> {
235 use super::community_view::community_user_ban_view::dsl::*;
236 community_user_ban_view
237 .filter(user_id.eq(from_user_id))
238 .filter(community_id.eq(from_community_id))
244 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
245 #[table_name="site_view"]
246 pub struct SiteView {
249 pub description: Option<String>,
251 pub published: chrono::NaiveDateTime,
252 pub updated: Option<chrono::NaiveDateTime>,
253 pub creator_name: String,
254 pub number_of_users: i64,
255 pub number_of_posts: i64,
256 pub number_of_comments: i64,
257 pub number_of_communities: i64,
261 pub fn read(conn: &PgConnection) -> Result<Self, Error> {
262 use super::community_view::site_view::dsl::*;
263 site_view.first::<Self>(conn)