2021-10-16 13:33:38 +00:00
|
|
|
use crate::{
|
|
|
|
source::community_block::{CommunityBlock, CommunityBlockForm},
|
|
|
|
traits::Blockable,
|
|
|
|
};
|
2021-08-19 20:54:15 +00:00
|
|
|
use diesel::{dsl::*, result::Error, *};
|
|
|
|
|
|
|
|
impl Blockable for CommunityBlock {
|
|
|
|
type Form = CommunityBlockForm;
|
2022-09-26 14:09:32 +00:00
|
|
|
fn block(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::schema::community_block::dsl::*;
|
2021-08-19 20:54:15 +00:00
|
|
|
insert_into(community_block)
|
|
|
|
.values(community_block_form)
|
|
|
|
.on_conflict((person_id, community_id))
|
|
|
|
.do_update()
|
|
|
|
.set(community_block_form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
2022-09-26 14:09:32 +00:00
|
|
|
fn unblock(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
|
2021-10-16 13:33:38 +00:00
|
|
|
use crate::schema::community_block::dsl::*;
|
2021-08-19 20:54:15 +00:00
|
|
|
diesel::delete(
|
|
|
|
community_block
|
|
|
|
.filter(person_id.eq(community_block_form.person_id))
|
|
|
|
.filter(community_id.eq(community_block_form.community_id)),
|
|
|
|
)
|
|
|
|
.execute(conn)
|
|
|
|
}
|
|
|
|
}
|