Move get_followers to relationships::queries module

This commit is contained in:
silverpill 2022-01-02 13:42:10 +00:00
parent e2b5147502
commit c11cd26961
4 changed files with 23 additions and 22 deletions

View file

@ -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,

View file

@ -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(

View file

@ -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<Vec<DbActorProfile>, 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::<Result<Vec<DbActorProfile>, _>>()?;
Ok(profiles)
}
/// Deletes profile from database and returns collection of orphaned objects.
pub async fn delete_profile(
db_client: &mut impl GenericClient,

View file

@ -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<Vec<DbActorProfile>, 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::<Result<_, _>>()?;
Ok(profiles)
}