2022-05-03 17:44:13 +00:00
|
|
|
use crate::structs::CommunityPersonBanView;
|
2023-10-13 13:48:18 +00:00
|
|
|
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
|
2022-11-09 10:05:00 +00:00
|
|
|
use diesel_async::RunQueryDsl;
|
2021-03-10 22:33:55 +00:00
|
|
|
use lemmy_db_schema::{
|
2021-10-16 13:33:38 +00:00
|
|
|
newtypes::{CommunityId, PersonId},
|
2023-10-13 13:48:18 +00:00
|
|
|
schema::community_person_ban,
|
2022-11-09 10:05:00 +00:00
|
|
|
utils::{get_conn, DbPool},
|
2021-03-10 22:33:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
impl CommunityPersonBanView {
|
2022-11-09 10:05:00 +00:00
|
|
|
pub async fn get(
|
2023-07-11 13:09:59 +00:00
|
|
|
pool: &mut DbPool<'_>,
|
2021-03-18 20:25:21 +00:00
|
|
|
from_person_id: PersonId,
|
|
|
|
from_community_id: CommunityId,
|
2023-10-13 13:48:18 +00:00
|
|
|
) -> Result<bool, Error> {
|
2022-11-09 10:05:00 +00:00
|
|
|
let conn = &mut get_conn(pool).await?;
|
2023-10-13 13:48:18 +00:00
|
|
|
select(exists(
|
|
|
|
community_person_ban::table
|
|
|
|
.filter(community_person_ban::community_id.eq(from_community_id))
|
|
|
|
.filter(community_person_ban::person_id.eq(from_person_id)),
|
|
|
|
))
|
|
|
|
.get_result::<bool>(conn)
|
|
|
|
.await
|
2021-03-10 22:33:55 +00:00
|
|
|
}
|
|
|
|
}
|