mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-04 11:08:44 +00:00
6f3bf4634b
* Various pedantic clippy fixes * more clippy pedantic fixes * try to fix ci * add fix clippy script, use rust 1.65 * fix clippy
34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
use crate::{
|
|
schema::community_block::dsl::{community_block, community_id, person_id},
|
|
source::community_block::{CommunityBlock, CommunityBlockForm},
|
|
traits::Blockable,
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
#[async_trait]
|
|
impl Blockable for CommunityBlock {
|
|
type Form = CommunityBlockForm;
|
|
async fn block(pool: &DbPool, community_block_form: &Self::Form) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
insert_into(community_block)
|
|
.values(community_block_form)
|
|
.on_conflict((person_id, community_id))
|
|
.do_update()
|
|
.set(community_block_form)
|
|
.get_result::<Self>(conn)
|
|
.await
|
|
}
|
|
async fn unblock(pool: &DbPool, community_block_form: &Self::Form) -> Result<usize, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
diesel::delete(
|
|
community_block
|
|
.filter(person_id.eq(community_block_form.person_id))
|
|
.filter(community_id.eq(community_block_form.community_id)),
|
|
)
|
|
.execute(conn)
|
|
.await
|
|
}
|
|
}
|