X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Fimpls%2Fperson.rs;h=de99d4b63dc2223a58daa749636ea9085a34404a;hb=c9f140742925d6da20103124b49f2b58a35fc2b8;hp=6e4398f6834fafcc3fcb051b79daf80fcd7c06ee;hpb=4e6409f325bca5b2727b19c24d77ffa2b59109b1;p=lemmy.git diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 6e4398f6..de99d4b6 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -66,124 +66,26 @@ mod safe_type { } } -mod safe_type_alias_1 { - use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe}; - - type Columns = ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ); - - impl ToSafe for PersonAlias1 { - type SafeColumns = Columns; - fn safe_columns_tuple() -> Self::SafeColumns { - ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ) - } - } -} - -mod safe_type_alias_2 { - use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe}; - - type Columns = ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ); - - impl ToSafe for PersonAlias2 { - type SafeColumns = Columns; - fn safe_columns_tuple() -> Self::SafeColumns { - ( - id, - name, - display_name, - avatar, - banned, - published, - updated, - actor_id, - bio, - local, - banner, - deleted, - inbox_url, - shared_inbox_url, - matrix_user_id, - admin, - bot_account, - ban_expires, - ) - } - } -} - impl Crud for Person { type Form = PersonForm; type IdType = PersonId; - fn read(conn: &PgConnection, person_id: PersonId) -> Result { + fn read(conn: &mut PgConnection, person_id: PersonId) -> Result { person .filter(deleted.eq(false)) .find(person_id) .first::(conn) } - fn delete(conn: &PgConnection, person_id: PersonId) -> Result { + fn delete(conn: &mut PgConnection, person_id: PersonId) -> Result { diesel::delete(person.find(person_id)).execute(conn) } - fn create(conn: &PgConnection, form: &PersonForm) -> Result { + fn create(conn: &mut PgConnection, form: &PersonForm) -> Result { insert_into(person).values(form).get_result::(conn) } - fn update(conn: &PgConnection, person_id: PersonId, form: &PersonForm) -> Result { + fn update( + conn: &mut PgConnection, + person_id: PersonId, + form: &PersonForm, + ) -> Result { diesel::update(person.find(person_id)) .set(form) .get_result::(conn) @@ -192,7 +94,7 @@ impl Crud for Person { impl Person { pub fn ban_person( - conn: &PgConnection, + conn: &mut PgConnection, person_id: PersonId, ban: bool, expires: Option, @@ -202,19 +104,23 @@ impl Person { .get_result::(conn) } - pub fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result { + pub fn add_admin( + conn: &mut PgConnection, + person_id: PersonId, + added: bool, + ) -> Result { diesel::update(person.find(person_id)) .set(admin.eq(added)) .get_result::(conn) } - pub fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result { + pub fn mark_as_updated(conn: &mut PgConnection, person_id: PersonId) -> Result { diesel::update(person.find(person_id)) .set((last_refreshed_at.eq(naive_now()),)) .get_result::(conn) } - pub fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result { + pub fn delete_account(conn: &mut PgConnection, person_id: PersonId) -> Result { use crate::schema::local_user; // Set the local user info to none @@ -238,7 +144,7 @@ impl Person { .get_result::(conn) } - pub fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result { + pub fn upsert(conn: &mut PgConnection, person_form: &PersonForm) -> Result { insert_into(person) .values(person_form) .on_conflict(actor_id) @@ -248,7 +154,7 @@ impl Person { } pub fn update_deleted( - conn: &PgConnection, + conn: &mut PgConnection, person_id: PersonId, new_deleted: bool, ) -> Result { @@ -258,13 +164,16 @@ impl Person { .get_result::(conn) } - pub fn leave_admin(conn: &PgConnection, person_id: PersonId) -> Result { + pub fn leave_admin(conn: &mut PgConnection, person_id: PersonId) -> Result { diesel::update(person.find(person_id)) .set(admin.eq(false)) .get_result::(conn) } - pub fn remove_avatar_and_banner(conn: &PgConnection, person_id: PersonId) -> Result { + pub fn remove_avatar_and_banner( + conn: &mut PgConnection, + person_id: PersonId, + ) -> Result { diesel::update(person.find(person_id)) .set(( avatar.eq::>(None), @@ -283,7 +192,7 @@ pub fn is_banned(banned_: bool, expires: Option) -> bool } impl ApubActor for Person { - 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::person::dsl::*; Ok( person @@ -296,7 +205,7 @@ impl ApubActor for Person { } fn read_from_name( - conn: &PgConnection, + conn: &mut PgConnection, from_name: &str, include_deleted: bool, ) -> Result { @@ -311,7 +220,7 @@ impl ApubActor for Person { } fn read_from_name_and_domain( - conn: &PgConnection, + conn: &mut PgConnection, person_name: &str, protocol_domain: &str, ) -> Result { @@ -329,7 +238,7 @@ mod tests { #[test] fn test_crud() { - let conn = establish_unpooled_connection(); + let conn = &mut establish_unpooled_connection(); let new_person = PersonForm { name: "holly".into(), @@ -337,7 +246,7 @@ mod tests { ..PersonForm::default() }; - let inserted_person = Person::create(&conn, &new_person).unwrap(); + let inserted_person = Person::create(conn, &new_person).unwrap(); let expected_person = Person { id: inserted_person.id, @@ -363,9 +272,9 @@ mod tests { ban_expires: None, }; - let read_person = Person::read(&conn, inserted_person.id).unwrap(); - let updated_person = Person::update(&conn, inserted_person.id, &new_person).unwrap(); - let num_deleted = Person::delete(&conn, inserted_person.id).unwrap(); + let read_person = Person::read(conn, inserted_person.id).unwrap(); + let updated_person = Person::update(conn, inserted_person.id, &new_person).unwrap(); + let num_deleted = Person::delete(conn, inserted_person.id).unwrap(); assert_eq!(expected_person, read_person); assert_eq!(expected_person, inserted_person);