1 use crate::structs::{ModTransferCommunityView, ModlogListParams};
8 NullableExpressionMethods,
11 use diesel_async::RunQueryDsl;
12 use lemmy_db_schema::{
14 schema::{community, mod_transfer_community, person},
16 community::{Community, CommunitySafe},
17 moderator::ModTransferCommunity,
18 person::{Person, PersonSafe},
20 traits::{ToSafe, ViewToVec},
21 utils::{get_conn, limit_and_offset, DbPool},
24 type ModTransferCommunityViewTuple = (
31 impl ModTransferCommunityView {
32 pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
33 let conn = &mut get_conn(pool).await?;
35 let person_alias_1 = diesel::alias!(person as person1);
36 let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
37 let show_mod_names = !params.hide_modlog_names;
38 let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
40 let admin_names_join = mod_transfer_community::mod_person_id
42 .and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
43 let mut query = mod_transfer_community::table
44 .left_join(person::table.on(admin_names_join))
45 .inner_join(community::table)
48 .on(mod_transfer_community::other_person_id.eq(person_alias_1.field(person::id))),
51 mod_transfer_community::all_columns,
52 Person::safe_columns_tuple().nullable(),
53 Community::safe_columns_tuple(),
54 person_alias_1.fields(Person::safe_columns_tuple()),
58 if let Some(mod_person_id) = params.mod_person_id {
59 query = query.filter(mod_transfer_community::mod_person_id.eq(mod_person_id));
62 if let Some(community_id) = params.community_id {
63 query = query.filter(mod_transfer_community::community_id.eq(community_id));
66 if let Some(other_person_id) = params.other_person_id {
67 query = query.filter(person_alias_1.field(person::id).eq(other_person_id));
70 let (limit, offset) = limit_and_offset(params.page, params.limit)?;
75 .order_by(mod_transfer_community::when_.desc())
76 .load::<ModTransferCommunityViewTuple>(conn)
79 let results = Self::from_tuple_to_vec(res);
84 impl ViewToVec for ModTransferCommunityView {
85 type DbTuple = ModTransferCommunityViewTuple;
86 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
90 mod_transfer_community: a.0,
95 .collect::<Vec<Self>>()