From c11cd26961536e28e328e2193453c9a56fc1fb99 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 2 Jan 2022 13:42:10 +0000 Subject: [PATCH] Move get_followers to relationships::queries module --- src/mastodon_api/accounts/views.rs | 2 +- src/mastodon_api/statuses/helpers.rs | 2 +- src/models/profiles/queries.rs | 20 -------------------- src/models/relationships/queries.rs | 21 +++++++++++++++++++++ 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index ca189cc..9180fe6 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -23,7 +23,6 @@ use crate::mastodon_api::statuses::types::Status; use crate::mastodon_api::timelines::types::TimelineQueryParams; use crate::models::posts::queries::get_posts_by_author; use crate::models::profiles::queries::{ - get_followers, get_profile_by_id, update_profile, }; @@ -31,6 +30,7 @@ use crate::models::relationships::queries::{ create_follow_request, follow, get_follow_request_by_path, + get_followers, get_relationship, get_relationships, unfollow, diff --git a/src/mastodon_api/statuses/helpers.rs b/src/mastodon_api/statuses/helpers.rs index fdb9def..0c18227 100644 --- a/src/mastodon_api/statuses/helpers.rs +++ b/src/mastodon_api/statuses/helpers.rs @@ -2,9 +2,9 @@ use tokio_postgres::GenericClient; use crate::activitypub::actor::Actor; use crate::errors::DatabaseError; -use crate::models::profiles::queries::get_followers; use crate::models::posts::queries::get_post_author; use crate::models::posts::types::Post; +use crate::models::relationships::queries::get_followers; use crate::models::users::types::User; pub async fn get_note_audience( diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 5045e71..9878b08 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -182,26 +182,6 @@ pub async fn get_profiles_by_accts( Ok(profiles) } -pub async fn get_followers( - db_client: &impl GenericClient, - profile_id: &Uuid, -) -> Result, DatabaseError> { - let rows = db_client.query( - " - SELECT actor_profile - FROM actor_profile - JOIN relationship - ON (actor_profile.id = relationship.source_id) - WHERE relationship.target_id = $1 - ", - &[&profile_id], - ).await?; - let profiles = rows.iter() - .map(|row| row.try_get("actor_profile")) - .collect::, _>>()?; - Ok(profiles) -} - /// Deletes profile from database and returns collection of orphaned objects. pub async fn delete_profile( db_client: &mut impl GenericClient, diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index bcad411..eb5bd64 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -10,6 +10,7 @@ use crate::models::profiles::queries::{ update_follower_count, update_following_count, }; +use crate::models::profiles::types::DbActorProfile; use crate::utils::id::new_uuid; use super::types::{ DbFollowRequest, @@ -237,3 +238,23 @@ pub async fn get_follow_request_by_path( let request: DbFollowRequest = row.try_get("follow_request")?; Ok(request) } + +pub async fn get_followers( + db_client: &impl GenericClient, + profile_id: &Uuid, +) -> Result, DatabaseError> { + let rows = db_client.query( + " + SELECT actor_profile + FROM actor_profile + JOIN relationship + ON (actor_profile.id = relationship.source_id) + WHERE relationship.target_id = $1 + ", + &[&profile_id], + ).await?; + let profiles = rows.iter() + .map(|row| row.try_get("actor_profile")) + .collect::>()?; + Ok(profiles) +}