1 use crate::structs::AdminPurgeCommentView;
2 use diesel::{result::Error, *};
5 schema::{admin_purge_comment, person, post},
7 moderator::AdminPurgeComment,
8 person::{Person, PersonSafe},
11 traits::{ToSafe, ViewToVec},
12 utils::limit_and_offset,
15 type AdminPurgeCommentViewTuple = (AdminPurgeComment, PersonSafe, Post);
17 impl AdminPurgeCommentView {
20 admin_person_id: Option<PersonId>,
23 ) -> Result<Vec<Self>, Error> {
24 let mut query = admin_purge_comment::table
25 .inner_join(person::table.on(admin_purge_comment::admin_person_id.eq(person::id)))
26 .inner_join(post::table)
28 admin_purge_comment::all_columns,
29 Person::safe_columns_tuple(),
34 if let Some(admin_person_id) = admin_person_id {
35 query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
38 let (limit, offset) = limit_and_offset(page, limit)?;
43 .order_by(admin_purge_comment::when_.desc())
44 .load::<AdminPurgeCommentViewTuple>(conn)?;
46 Ok(Self::from_tuple_to_vec(res))
50 impl ViewToVec for AdminPurgeCommentView {
51 type DbTuple = AdminPurgeCommentViewTuple;
52 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
56 admin_purge_comment: a.0.to_owned(),
57 admin: a.1.to_owned(),
60 .collect::<Vec<Self>>()