X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_views_actor%2Fsrc%2Fcommunity_follower_view.rs;h=ccc7ae706790f7df35a6ad19beb4d42905293b15;hb=985fe24669d3fdeecc0aa76cc74dd6570cbad5c8;hp=3b03b027d86bcd4cc4c88a5efb0189776700d091;hpb=48f187188bce9f5fa1ac8ee09615540ee4df8540;p=lemmy.git diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index 3b03b027..ccc7ae70 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -4,15 +4,12 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommunityId, PersonId}, schema::{community, community_follower, person}, - source::{ - community::{Community, CommunitySafe}, - person::{Person, PersonSafe}, - }, - traits::{ToSafe, ViewToVec}, + source::{community::Community, person::Person}, + traits::JoinView, utils::{get_conn, DbPool}, }; -type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe); +type CommunityFollowerViewTuple = (Community, Person); impl CommunityFollowerView { pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result, Error> { @@ -20,16 +17,13 @@ impl CommunityFollowerView { let res = community_follower::table .inner_join(community::table) .inner_join(person::table) - .select(( - Community::safe_columns_tuple(), - Person::safe_columns_tuple(), - )) + .select((community::all_columns, person::all_columns)) .filter(community_follower::community_id.eq(community_id)) .order_by(community::title) .load::(conn) .await?; - Ok(Self::from_tuple_to_vec(res)) + Ok(res.into_iter().map(Self::from_tuple).collect()) } pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result, Error> { @@ -37,10 +31,7 @@ impl CommunityFollowerView { let res = community_follower::table .inner_join(community::table) .inner_join(person::table) - .select(( - Community::safe_columns_tuple(), - Person::safe_columns_tuple(), - )) + .select((community::all_columns, person::all_columns)) .filter(community_follower::person_id.eq(person_id)) .filter(community::deleted.eq(false)) .filter(community::removed.eq(false)) @@ -48,19 +39,16 @@ impl CommunityFollowerView { .load::(conn) .await?; - Ok(Self::from_tuple_to_vec(res)) + Ok(res.into_iter().map(Self::from_tuple).collect()) } } -impl ViewToVec for CommunityFollowerView { - type DbTuple = CommunityFollowerViewTuple; - fn from_tuple_to_vec(items: Vec) -> Vec { - items - .into_iter() - .map(|a| Self { - community: a.0, - follower: a.1, - }) - .collect::>() +impl JoinView for CommunityFollowerView { + type JoinTuple = CommunityFollowerViewTuple; + fn from_tuple(a: Self::JoinTuple) -> Self { + Self { + community: a.0, + follower: a.1, + } } }