2021-03-10 15:33:55 -07:00
|
|
|
use diesel::{result::Error, *};
|
|
|
|
use lemmy_db_schema::{
|
2021-10-16 07:33:38 -06:00
|
|
|
newtypes::{CommunityId, PersonId},
|
2021-03-10 15:33:55 -07:00
|
|
|
schema::{community, community_person_ban, person},
|
|
|
|
source::{
|
|
|
|
community::{Community, CommunitySafe},
|
2021-03-10 21:43:11 -07:00
|
|
|
person::{Person, PersonSafe},
|
2021-03-10 15:33:55 -07:00
|
|
|
},
|
2021-10-16 07:33:38 -06:00
|
|
|
traits::ToSafe,
|
2021-03-10 15:33:55 -07:00
|
|
|
};
|
2021-10-19 10:37:01 -06:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-03-10 15:33:55 -07:00
|
|
|
|
2021-10-19 10:37:01 -06:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2021-03-10 15:33:55 -07:00
|
|
|
pub struct CommunityPersonBanView {
|
|
|
|
pub community: CommunitySafe,
|
|
|
|
pub person: PersonSafe,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CommunityPersonBanView {
|
|
|
|
pub fn get(
|
|
|
|
conn: &PgConnection,
|
2021-03-18 14:25:21 -06:00
|
|
|
from_person_id: PersonId,
|
|
|
|
from_community_id: CommunityId,
|
2021-03-10 15:33:55 -07:00
|
|
|
) -> Result<Self, Error> {
|
|
|
|
let (community, person) = community_person_ban::table
|
|
|
|
.inner_join(community::table)
|
|
|
|
.inner_join(person::table)
|
2021-03-10 21:43:11 -07:00
|
|
|
.select((
|
|
|
|
Community::safe_columns_tuple(),
|
|
|
|
Person::safe_columns_tuple(),
|
|
|
|
))
|
2021-03-10 15:33:55 -07:00
|
|
|
.filter(community_person_ban::community_id.eq(from_community_id))
|
|
|
|
.filter(community_person_ban::person_id.eq(from_person_id))
|
|
|
|
.order_by(community_person_ban::published)
|
|
|
|
.first::<(CommunitySafe, PersonSafe)>(conn)?;
|
|
|
|
|
|
|
|
Ok(CommunityPersonBanView { community, person })
|
|
|
|
}
|
|
|
|
}
|