X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Fimpls%2Fcommunity.rs;h=574c0ee2d23536e0edc8d119007dd1d4fcd5f615;hb=c9f140742925d6da20103124b49f2b58a35fc2b8;hp=eb92d7a0b3c181ccebed138a1740cb267807bdd5;hpb=4e6409f325bca5b2727b19c24d77ffa2b59109b1;p=lemmy.git diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index eb92d7a0..574c0ee2 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -73,17 +73,17 @@ mod safe_type { impl Crud for Community { type Form = CommunityForm; type IdType = CommunityId; - fn read(conn: &PgConnection, community_id: CommunityId) -> Result { + fn read(conn: &mut PgConnection, community_id: CommunityId) -> Result { use crate::schema::community::dsl::*; community.find(community_id).first::(conn) } - fn delete(conn: &PgConnection, community_id: CommunityId) -> Result { + fn delete(conn: &mut PgConnection, community_id: CommunityId) -> Result { use crate::schema::community::dsl::*; diesel::delete(community.find(community_id)).execute(conn) } - fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result { + fn create(conn: &mut PgConnection, new_community: &CommunityForm) -> Result { use crate::schema::community::dsl::*; insert_into(community) .values(new_community) @@ -91,7 +91,7 @@ impl Crud for Community { } fn update( - conn: &PgConnection, + conn: &mut PgConnection, community_id: CommunityId, new_community: &CommunityForm, ) -> Result { @@ -104,7 +104,7 @@ impl Crud for Community { impl Community { pub fn update_deleted( - conn: &PgConnection, + conn: &mut PgConnection, community_id: CommunityId, new_deleted: bool, ) -> Result { @@ -115,7 +115,7 @@ impl Community { } pub fn update_removed( - conn: &PgConnection, + conn: &mut PgConnection, community_id: CommunityId, new_removed: bool, ) -> Result { @@ -125,12 +125,15 @@ impl Community { .get_result::(conn) } - pub fn distinct_federated_communities(conn: &PgConnection) -> Result, Error> { + pub fn distinct_federated_communities(conn: &mut PgConnection) -> Result, Error> { use crate::schema::community::dsl::*; community.select(actor_id).distinct().load::(conn) } - pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result { + pub fn upsert( + conn: &mut PgConnection, + community_form: &CommunityForm, + ) -> Result { use crate::schema::community::dsl::*; insert_into(community) .values(community_form) @@ -141,7 +144,7 @@ impl Community { } pub fn remove_avatar_and_banner( - conn: &PgConnection, + conn: &mut PgConnection, community_id: CommunityId, ) -> Result { use crate::schema::community::dsl::*; @@ -157,7 +160,7 @@ impl Community { impl Joinable for CommunityModerator { type Form = CommunityModeratorForm; fn join( - conn: &PgConnection, + conn: &mut PgConnection, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::*; @@ -167,7 +170,7 @@ impl Joinable for CommunityModerator { } fn leave( - conn: &PgConnection, + conn: &mut PgConnection, community_moderator_form: &CommunityModeratorForm, ) -> Result { use crate::schema::community_moderator::dsl::*; @@ -202,7 +205,7 @@ impl DeleteableOrRemoveable for Community { impl CommunityModerator { pub fn delete_for_community( - conn: &PgConnection, + conn: &mut PgConnection, for_community_id: CommunityId, ) -> Result { use crate::schema::community_moderator::dsl::*; @@ -210,7 +213,7 @@ impl CommunityModerator { } pub fn get_person_moderated_communities( - conn: &PgConnection, + conn: &mut PgConnection, for_person_id: PersonId, ) -> Result, Error> { use crate::schema::community_moderator::dsl::*; @@ -224,7 +227,7 @@ impl CommunityModerator { impl Bannable for CommunityPersonBan { type Form = CommunityPersonBanForm; fn ban( - conn: &PgConnection, + conn: &mut PgConnection, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::*; @@ -237,7 +240,7 @@ impl Bannable for CommunityPersonBan { } fn unban( - conn: &PgConnection, + conn: &mut PgConnection, community_person_ban_form: &CommunityPersonBanForm, ) -> Result { use crate::schema::community_person_ban::dsl::*; @@ -269,7 +272,7 @@ impl CommunityFollower { impl Followable for CommunityFollower { type Form = CommunityFollowerForm; fn follow( - conn: &PgConnection, + conn: &mut PgConnection, community_follower_form: &CommunityFollowerForm, ) -> Result { use crate::schema::community_follower::dsl::*; @@ -281,7 +284,7 @@ impl Followable for CommunityFollower { .get_result::(conn) } fn follow_accepted( - conn: &PgConnection, + conn: &mut PgConnection, community_id_: CommunityId, person_id_: PersonId, ) -> Result @@ -298,7 +301,7 @@ impl Followable for CommunityFollower { .get_result::(conn) } fn unfollow( - conn: &PgConnection, + conn: &mut PgConnection, community_follower_form: &CommunityFollowerForm, ) -> Result { use crate::schema::community_follower::dsl::*; @@ -311,7 +314,10 @@ impl Followable for CommunityFollower { } // TODO: this function name only makes sense if you call it with a remote community. for a local // community, it will also return true if only remote followers exist - fn has_local_followers(conn: &PgConnection, community_id_: CommunityId) -> Result { + fn has_local_followers( + conn: &mut PgConnection, + community_id_: CommunityId, + ) -> Result { use crate::schema::community_follower::dsl::*; diesel::select(exists( community_follower.filter(community_id.eq(community_id_)), @@ -321,7 +327,7 @@ impl Followable for CommunityFollower { } impl ApubActor for Community { - fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result, Error> { + fn read_from_apub_id(conn: &mut PgConnection, object_id: &DbUrl) -> Result, Error> { use crate::schema::community::dsl::*; Ok( community @@ -333,7 +339,7 @@ impl ApubActor for Community { } fn read_from_name( - conn: &PgConnection, + conn: &mut PgConnection, community_name: &str, include_deleted: bool, ) -> Result { @@ -349,7 +355,7 @@ impl ApubActor for Community { } fn read_from_name_and_domain( - conn: &PgConnection, + conn: &mut PgConnection, community_name: &str, protocol_domain: &str, ) -> Result { @@ -373,7 +379,7 @@ mod tests { #[test] #[serial] fn test_crud() { - let conn = establish_unpooled_connection(); + let conn = &mut establish_unpooled_connection(); let new_person = PersonForm { name: "bobbee".into(), @@ -381,7 +387,7 @@ mod tests { ..PersonForm::default() }; - let inserted_person = Person::create(&conn, &new_person).unwrap(); + let inserted_person = Person::create(conn, &new_person).unwrap(); let new_community = CommunityForm { name: "TIL".into(), @@ -390,7 +396,7 @@ mod tests { ..CommunityForm::default() }; - let inserted_community = Community::create(&conn, &new_community).unwrap(); + let inserted_community = Community::create(conn, &new_community).unwrap(); let expected_community = Community { id: inserted_community.id, @@ -423,7 +429,7 @@ mod tests { }; let inserted_community_follower = - CommunityFollower::follow(&conn, &community_follower_form).unwrap(); + CommunityFollower::follow(conn, &community_follower_form).unwrap(); let expected_community_follower = CommunityFollower { id: inserted_community_follower.id, @@ -439,7 +445,7 @@ mod tests { }; let inserted_community_moderator = - CommunityModerator::join(&conn, &community_moderator_form).unwrap(); + CommunityModerator::join(conn, &community_moderator_form).unwrap(); let expected_community_moderator = CommunityModerator { id: inserted_community_moderator.id, @@ -455,7 +461,7 @@ mod tests { }; let inserted_community_person_ban = - CommunityPersonBan::ban(&conn, &community_person_ban_form).unwrap(); + CommunityPersonBan::ban(conn, &community_person_ban_form).unwrap(); let expected_community_person_ban = CommunityPersonBan { id: inserted_community_person_ban.id, @@ -465,14 +471,13 @@ mod tests { expires: None, }; - let read_community = Community::read(&conn, inserted_community.id).unwrap(); - let updated_community = - Community::update(&conn, inserted_community.id, &new_community).unwrap(); - let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap(); - let left_community = CommunityModerator::leave(&conn, &community_moderator_form).unwrap(); - let unban = CommunityPersonBan::unban(&conn, &community_person_ban_form).unwrap(); - let num_deleted = Community::delete(&conn, inserted_community.id).unwrap(); - Person::delete(&conn, inserted_person.id).unwrap(); + let read_community = Community::read(conn, inserted_community.id).unwrap(); + let updated_community = Community::update(conn, inserted_community.id, &new_community).unwrap(); + let ignored_community = CommunityFollower::unfollow(conn, &community_follower_form).unwrap(); + let left_community = CommunityModerator::leave(conn, &community_moderator_form).unwrap(); + let unban = CommunityPersonBan::unban(conn, &community_person_ban_form).unwrap(); + let num_deleted = Community::delete(conn, inserted_community.id).unwrap(); + Person::delete(conn, inserted_person.id).unwrap(); assert_eq!(expected_community, read_community); assert_eq!(expected_community, inserted_community);