10 published -> Timestamp,
11 number_of_posts -> BigInt,
13 number_of_comments -> BigInt,
14 comment_score -> BigInt,
19 Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
21 #[table_name = "user_view"]
25 pub fedi_name: String,
28 pub published: chrono::NaiveDateTime,
29 pub number_of_posts: i64,
31 pub number_of_comments: i64,
32 pub comment_score: i64,
39 search_term: Option<String>,
42 ) -> Result<Vec<Self>, Error> {
43 use super::user_view::user_view::dsl::*;
45 let (limit, offset) = limit_and_offset(page, limit);
47 let mut query = user_view.into_boxed();
49 if let Some(search_term) = search_term {
50 query = query.filter(name.ilike(fuzzy_search(&search_term)));
54 SortType::Hot => query
55 .order_by(comment_score.desc())
56 .then_order_by(published.desc()),
57 SortType::New => query.order_by(published.desc()),
58 SortType::TopAll => query.order_by(comment_score.desc()),
59 SortType::TopYear => query
60 .filter(published.gt(now - 1.years()))
61 .order_by(comment_score.desc()),
62 SortType::TopMonth => query
63 .filter(published.gt(now - 1.months()))
64 .order_by(comment_score.desc()),
65 SortType::TopWeek => query
66 .filter(published.gt(now - 1.weeks()))
67 .order_by(comment_score.desc()),
68 SortType::TopDay => query
69 .filter(published.gt(now - 1.days()))
70 .order_by(comment_score.desc()),
73 query = query.limit(limit).offset(offset);
75 query.load::<Self>(conn)
78 pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
79 use super::user_view::user_view::dsl::*;
81 user_view.find(from_user_id).first::<Self>(conn)
84 pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
85 use super::user_view::user_view::dsl::*;
86 user_view.filter(admin.eq(true)).load::<Self>(conn)
89 pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
90 use super::user_view::user_view::dsl::*;
91 user_view.filter(banned.eq(true)).load::<Self>(conn)