1 use diesel::{result::Error, *};
2 use lemmy_db_queries::ToSafe;
4 schema::{community, community_user_ban, user_},
6 community::{Community, CommunitySafe},
7 user::{UserSafe, User_},
12 #[derive(Debug, Serialize, Clone)]
13 pub struct CommunityUserBanView {
14 pub community: CommunitySafe,
18 impl CommunityUserBanView {
22 from_community_id: i32,
23 ) -> Result<Self, Error> {
24 let (community, user) = community_user_ban::table
25 .inner_join(community::table)
26 .inner_join(user_::table)
27 .select((Community::safe_columns_tuple(), User_::safe_columns_tuple()))
28 .filter(community_user_ban::community_id.eq(from_community_id))
29 .filter(community_user_ban::user_id.eq(from_user_id))
30 .order_by(community_user_ban::published)
31 .first::<(CommunitySafe, UserSafe)>(conn)?;
33 Ok(CommunityUserBanView { community, user })