1 use diesel::{result::Error, *};
2 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
4 schema::{community, mod_remove_community, user_},
6 community::{Community, CommunitySafe},
7 moderator::ModRemoveCommunity,
8 user::{UserSafe, User_},
13 #[derive(Debug, Serialize, Clone)]
14 pub struct ModRemoveCommunityView {
15 pub mod_remove_community: ModRemoveCommunity,
16 pub moderator: UserSafe,
17 pub community: CommunitySafe,
20 type ModRemoveCommunityTuple = (ModRemoveCommunity, UserSafe, CommunitySafe);
22 impl ModRemoveCommunityView {
25 mod_user_id: Option<i32>,
28 ) -> Result<Vec<Self>, Error> {
29 let mut query = mod_remove_community::table
30 .inner_join(user_::table)
31 .inner_join(community::table)
33 mod_remove_community::all_columns,
34 User_::safe_columns_tuple(),
35 Community::safe_columns_tuple(),
39 if let Some(mod_user_id) = mod_user_id {
40 query = query.filter(mod_remove_community::mod_user_id.eq(mod_user_id));
43 let (limit, offset) = limit_and_offset(page, limit);
48 .order_by(mod_remove_community::when_.desc())
49 .load::<ModRemoveCommunityTuple>(conn)?;
51 Ok(Self::from_tuple_to_vec(res))
55 impl ViewToVec for ModRemoveCommunityView {
56 type DbTuple = ModRemoveCommunityTuple;
57 fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
61 mod_remove_community: a.0.to_owned(),
62 moderator: a.1.to_owned(),
63 community: a.2.to_owned(),
65 .collect::<Vec<Self>>()