1 use diesel::{result::Error, *};
2 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
4 schema::{community, mod_remove_community, person},
6 community::{Community, CommunitySafe},
7 moderator::ModRemoveCommunity,
8 person::{Person, PersonSafe},
14 #[derive(Debug, Serialize, Clone)]
15 pub struct ModRemoveCommunityView {
16 pub mod_remove_community: ModRemoveCommunity,
17 pub moderator: PersonSafe,
18 pub community: CommunitySafe,
21 type ModRemoveCommunityTuple = (ModRemoveCommunity, PersonSafe, CommunitySafe);
23 impl ModRemoveCommunityView {
26 mod_person_id: Option<PersonId>,
29 ) -> Result<Vec<Self>, Error> {
30 let mut query = mod_remove_community::table
31 .inner_join(person::table)
32 .inner_join(community::table)
34 mod_remove_community::all_columns,
35 Person::safe_columns_tuple(),
36 Community::safe_columns_tuple(),
40 if let Some(mod_person_id) = mod_person_id {
41 query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id));
44 let (limit, offset) = limit_and_offset(page, limit);
49 .order_by(mod_remove_community::when_.desc())
50 .load::<ModRemoveCommunityTuple>(conn)?;
52 Ok(Self::from_tuple_to_vec(res))
56 impl ViewToVec for ModRemoveCommunityView {
57 type DbTuple = ModRemoveCommunityTuple;
58 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
62 mod_remove_community: a.0.to_owned(),
63 moderator: a.1.to_owned(),
64 community: a.2.to_owned(),
66 .collect::<Vec<Self>>()