2019-05-05 05:20:38 +00:00
|
|
|
use super::*;
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
table! {
|
|
|
|
user_view (id) {
|
|
|
|
id -> Int4,
|
|
|
|
name -> Varchar,
|
|
|
|
fedi_name -> Varchar,
|
2019-04-16 23:04:23 +00:00
|
|
|
admin -> Bool,
|
|
|
|
banned -> Bool,
|
2019-04-08 05:19:02 +00:00
|
|
|
published -> Timestamp,
|
|
|
|
number_of_posts -> BigInt,
|
|
|
|
post_score -> BigInt,
|
|
|
|
number_of_comments -> BigInt,
|
|
|
|
comment_score -> BigInt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
|
|
|
|
#[table_name="user_view"]
|
|
|
|
pub struct UserView {
|
|
|
|
pub id: i32,
|
|
|
|
pub name: String,
|
|
|
|
pub fedi_name: String,
|
2019-04-16 23:04:23 +00:00
|
|
|
pub admin: bool,
|
|
|
|
pub banned: bool,
|
2019-04-08 05:19:02 +00:00
|
|
|
pub published: chrono::NaiveDateTime,
|
|
|
|
pub number_of_posts: i64,
|
|
|
|
pub post_score: i64,
|
|
|
|
pub number_of_comments: i64,
|
|
|
|
pub comment_score: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserView {
|
|
|
|
pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
|
2019-05-03 01:34:21 +00:00
|
|
|
use super::user_view::user_view::dsl::*;
|
2019-04-08 05:19:02 +00:00
|
|
|
|
|
|
|
user_view.find(from_user_id)
|
|
|
|
.first::<Self>(conn)
|
|
|
|
}
|
2019-04-16 23:04:23 +00:00
|
|
|
|
|
|
|
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
2019-05-03 01:34:21 +00:00
|
|
|
use super::user_view::user_view::dsl::*;
|
2019-04-16 23:04:23 +00:00
|
|
|
user_view.filter(admin.eq(true))
|
|
|
|
.load::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
2019-05-03 01:34:21 +00:00
|
|
|
use super::user_view::user_view::dsl::*;
|
2019-04-16 23:04:23 +00:00
|
|
|
user_view.filter(banned.eq(true))
|
|
|
|
.load::<Self>(conn)
|
|
|
|
}
|
2019-04-08 05:19:02 +00:00
|
|
|
}
|
|
|
|
|