8 description -> Nullable<Text>,
12 published -> Timestamp,
13 updated -> Nullable<Timestamp>,
15 creator_name -> Varchar,
16 category_name -> Varchar,
17 number_of_subscribers -> BigInt,
18 number_of_posts -> BigInt,
19 number_of_comments -> BigInt,
21 user_id -> Nullable<Int4>,
22 subscribed -> Nullable<Bool>,
27 community_moderator_view (id) {
31 published -> Timestamp,
33 community_name -> Varchar,
38 community_follower_view (id) {
42 published -> Timestamp,
44 community_name -> Varchar,
49 community_user_ban_view (id) {
53 published -> Timestamp,
55 community_name -> Varchar,
63 description -> Nullable<Text>,
65 published -> Timestamp,
66 updated -> Nullable<Timestamp>,
67 creator_name -> Varchar,
68 number_of_users -> BigInt,
69 number_of_posts -> BigInt,
70 number_of_comments -> BigInt,
74 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
75 #[table_name="community_view"]
76 pub struct CommunityView {
80 pub description: Option<String>,
84 pub published: chrono::NaiveDateTime,
85 pub updated: Option<chrono::NaiveDateTime>,
87 pub creator_name: String,
88 pub category_name: String,
89 pub number_of_subscribers: i64,
90 pub number_of_posts: i64,
91 pub number_of_comments: i64,
93 pub user_id: Option<i32>,
94 pub subscribed: Option<bool>,
98 pub fn read(conn: &PgConnection, from_community_id: i32, from_user_id: Option<i32>) -> Result<Self, Error> {
99 use super::community_view::community_view::dsl::*;
101 let mut query = community_view.into_boxed();
103 query = query.filter(id.eq(from_community_id));
105 // The view lets you pass a null user_id, if you're not logged in
106 if let Some(from_user_id) = from_user_id {
107 query = query.filter(user_id.eq(from_user_id));
109 query = query.filter(user_id.is_null());
112 query.first::<Self>(conn)
115 pub fn list(conn: &PgConnection,
116 from_user_id: Option<i32>,
120 ) -> Result<Vec<Self>, Error> {
121 use super::community_view::community_view::dsl::*;
122 let mut query = community_view.into_boxed();
124 let (limit, offset) = limit_and_offset(page, limit);
126 // The view lets you pass a null user_id, if you're not logged in
128 SortType::Hot => query = query.order_by(hot_rank.desc()).filter(user_id.is_null()),
129 SortType::New => query = query.order_by(published.desc()).filter(user_id.is_null()),
130 SortType::TopAll => {
132 Some(from_user_id) => query = query.filter(user_id.eq(from_user_id)).order_by((subscribed.asc(), number_of_subscribers.desc())),
133 None => query = query.order_by(number_of_subscribers.desc()).filter(user_id.is_null())
142 .filter(removed.eq(false))
143 .filter(deleted.eq(false))
149 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
150 #[table_name="community_moderator_view"]
151 pub struct CommunityModeratorView {
153 pub community_id: i32,
155 pub published: chrono::NaiveDateTime,
156 pub user_name : String,
157 pub community_name: String,
160 impl CommunityModeratorView {
161 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
162 use super::community_view::community_moderator_view::dsl::*;
163 community_moderator_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
166 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
167 use super::community_view::community_moderator_view::dsl::*;
168 community_moderator_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
172 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
173 #[table_name="community_follower_view"]
174 pub struct CommunityFollowerView {
176 pub community_id: i32,
178 pub published: chrono::NaiveDateTime,
179 pub user_name : String,
180 pub community_name: String,
183 impl CommunityFollowerView {
184 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
185 use super::community_view::community_follower_view::dsl::*;
186 community_follower_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
189 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
190 use super::community_view::community_follower_view::dsl::*;
191 community_follower_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
196 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
197 #[table_name="community_user_ban_view"]
198 pub struct CommunityUserBanView {
200 pub community_id: i32,
202 pub published: chrono::NaiveDateTime,
203 pub user_name : String,
204 pub community_name: String,
207 impl CommunityUserBanView {
208 pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
209 use super::community_view::community_user_ban_view::dsl::*;
210 community_user_ban_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
213 pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
214 use super::community_view::community_user_ban_view::dsl::*;
215 community_user_ban_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
218 pub fn get(conn: &PgConnection, from_user_id: i32, from_community_id: i32) -> Result<Self, Error> {
219 use super::community_view::community_user_ban_view::dsl::*;
220 community_user_ban_view
221 .filter(user_id.eq(from_user_id))
222 .filter(community_id.eq(from_community_id))
228 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
229 #[table_name="site_view"]
230 pub struct SiteView {
233 pub description: Option<String>,
235 pub published: chrono::NaiveDateTime,
236 pub updated: Option<chrono::NaiveDateTime>,
237 pub creator_name: String,
238 pub number_of_users: i64,
239 pub number_of_posts: i64,
240 pub number_of_comments: i64,
244 pub fn read(conn: &PgConnection) -> Result<Self, Error> {
245 use super::community_view::site_view::dsl::*;
246 site_view.first::<Self>(conn)