]> Untitled Git - lemmy.git/blob - server/src/db/user_view.rs
Adding emoji support
[lemmy.git] / server / src / db / user_view.rs
1 use super::*;
2
3 table! {
4   user_view (id) {
5     id -> Int4,
6     name -> Varchar,
7     fedi_name -> Varchar,
8     admin -> Bool,
9     banned -> Bool,
10     published -> Timestamp,
11     number_of_posts -> BigInt,
12     post_score -> BigInt,
13     number_of_comments -> BigInt,
14     comment_score -> BigInt,
15   }
16 }
17
18 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
19 #[table_name="user_view"]
20 pub struct UserView {
21   pub id: i32,
22   pub name: String,
23   pub fedi_name: String,
24   pub admin: bool,
25   pub banned: bool,
26   pub published: chrono::NaiveDateTime,
27   pub number_of_posts: i64,
28   pub post_score: i64,
29   pub number_of_comments: i64,
30   pub comment_score: i64,
31 }
32
33 impl UserView {
34   pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
35     use super::user_view::user_view::dsl::*;
36
37     user_view.find(from_user_id)
38     .first::<Self>(conn)
39   }
40
41   pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
42     use super::user_view::user_view::dsl::*;
43     user_view.filter(admin.eq(true))
44     .load::<Self>(conn)
45   }
46
47   pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
48     use super::user_view::user_view::dsl::*;
49     user_view.filter(banned.eq(true))
50     .load::<Self>(conn)
51   }
52 }
53