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