1 use crate::structs::{AdminPurgeCommentView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{admin_purge_comment, person, post},
16 moderator::AdminPurgeComment,
17 person::{Person, PersonSafe},
20 traits::{ToSafe, ViewToVec},
21 utils::{get_conn, limit_and_offset, DbPool},
24 type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<PersonSafe>, Post);
26 impl AdminPurgeCommentView {
27 pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
28 let conn = &mut get_conn(pool).await?;
29 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
30 let show_mod_names = !params.hide_modlog_names;
31 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
33 let admin_names_join = admin_purge_comment::admin_person_id
35 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
37 let mut query = admin_purge_comment::table
38 .left_join(person::table.on(admin_names_join))
39 .inner_join(post::table)
41 admin_purge_comment::all_columns,
42 Person::safe_columns_tuple().nullable(),
47 if let Some(admin_person_id) = params.mod_person_id {
48 query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
51 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
56 .order_by(admin_purge_comment::when_.desc())
57 .load::<AdminPurgeCommentViewTuple>(conn)
60 let results = Self::from_tuple_to_vec(res);
65 impl ViewToVec for AdminPurgeCommentView {
66 type DbTuple = AdminPurgeCommentViewTuple;
67 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
71 admin_purge_comment: a.0,
75 .collect::<Vec<Self>>()