1 use diesel::{result::Error, *};
2 use lemmy_db_queries::ToSafe;
4 schema::{community, community_person_ban, person},
6 community::{Community, CommunitySafe},
7 person::{Person, PersonSafe},
12 #[derive(Debug, Serialize, Clone)]
13 pub struct CommunityPersonBanView {
14 pub community: CommunitySafe,
15 pub person: PersonSafe,
18 impl CommunityPersonBanView {
22 from_community_id: i32,
23 ) -> Result<Self, Error> {
24 let (community, person) = community_person_ban::table
25 .inner_join(community::table)
26 .inner_join(person::table)
28 Community::safe_columns_tuple(),
29 Person::safe_columns_tuple(),
31 .filter(community_person_ban::community_id.eq(from_community_id))
32 .filter(community_person_ban::person_id.eq(from_person_id))
33 .order_by(community_person_ban::published)
34 .first::<(CommunitySafe, PersonSafe)>(conn)?;
36 Ok(CommunityPersonBanView { community, person })