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},
14 #[derive(Debug, Serialize, Clone)]
15 pub struct CommunityPersonBanView {
16 pub community: CommunitySafe,
17 pub person: PersonSafe,
20 impl CommunityPersonBanView {
23 from_person_id: PersonId,
24 from_community_id: CommunityId,
25 ) -> Result<Self, Error> {
26 let (community, person) = community_person_ban::table
27 .inner_join(community::table)
28 .inner_join(person::table)
30 Community::safe_columns_tuple(),
31 Person::safe_columns_tuple(),
33 .filter(community_person_ban::community_id.eq(from_community_id))
34 .filter(community_person_ban::person_id.eq(from_person_id))
35 .order_by(community_person_ban::published)
36 .first::<(CommunitySafe, PersonSafe)>(conn)?;
38 Ok(CommunityPersonBanView { community, person })