1 use crate::structs::AdminPurgeCommunityView;
2 use diesel::{result::Error, *};
5 schema::{admin_purge_community, person},
7 moderator::AdminPurgeCommunity,
8 person::{Person, PersonSafe},
10 traits::{ToSafe, ViewToVec},
11 utils::limit_and_offset,
14 type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, PersonSafe);
16 impl AdminPurgeCommunityView {
19 admin_person_id: Option<PersonId>,
22 ) -> Result<Vec<Self>, Error> {
23 let mut query = admin_purge_community::table
24 .inner_join(person::table.on(admin_purge_community::admin_person_id.eq(person::id)))
26 admin_purge_community::all_columns,
27 Person::safe_columns_tuple(),
31 if let Some(admin_person_id) = admin_person_id {
32 query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id));
35 let (limit, offset) = limit_and_offset(page, limit)?;
40 .order_by(admin_purge_community::when_.desc())
41 .load::<AdminPurgeCommunityViewTuple>(conn)?;
43 Ok(Self::from_tuple_to_vec(res))
47 impl ViewToVec for AdminPurgeCommunityView {
48 type DbTuple = AdminPurgeCommunityViewTuple;
49 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
53 admin_purge_community: a.0.to_owned(),
54 admin: a.1.to_owned(),
56 .collect::<Vec<Self>>()