Remove get_relationships function and use get_relationship instead

This commit is contained in:
silverpill 2022-02-02 21:31:40 +00:00
parent 548e000b3e
commit a81d0ef216
3 changed files with 26 additions and 39 deletions

View file

@ -87,6 +87,27 @@ paths:
$ref: '#/components/schemas/Account'
400:
description: Invalid user data
/api/v1/accounts/relationships:
get:
summary: Find out whether a given actor is followed, blocked, muted, etc.
parameters:
- name: 'id[]'
in: query
description: Actor IDs to check
required: true
schema:
type: string
format: uuid
responses:
200:
description: Successful operation
content:
application/json:
schema:
description: Relationship list
type: array
items:
$ref: '#/components/schemas/Relationship'
/api/v1/accounts/{account_id}/statuses:
get:
summary: Posts created by the given actor.
@ -601,7 +622,7 @@ components:
type: object
properties:
id:
description: The account id.
description: Target profile id.
type: string
format: uuid
following:

View file

@ -33,7 +33,6 @@ use crate::models::relationships::queries::{
get_followers,
get_following,
get_relationship,
get_relationships,
unfollow,
};
use crate::models::users::queries::{
@ -185,12 +184,12 @@ async fn get_relationships_view(
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?;
let relationships = get_relationships(
let relationship = get_relationship(
db_client,
current_user.id,
vec![query_params.into_inner().id],
&current_user.id,
&query_params.id,
).await?;
Ok(HttpResponse::Ok().json(relationships))
Ok(HttpResponse::Ok().json(vec![relationship]))
}
#[post("/{account_id}/follow")]

View file

@ -18,39 +18,6 @@ use super::types::{
Relationship,
};
pub async fn get_relationships(
db_client: &impl GenericClient,
source_id: Uuid,
target_ids: Vec<Uuid>,
) -> Result<Vec<Relationship>, DatabaseError> {
let rows = db_client.query(
"
SELECT
actor_profile.id AS profile_id,
EXISTS (
SELECT 1 FROM relationship
WHERE source_id = $1 AND target_id = actor_profile.id
) AS following,
EXISTS (
SELECT 1 FROM relationship
WHERE source_id = actor_profile.id AND target_id = $1
) AS followed_by,
EXISTS (
SELECT 1 FROM follow_request
WHERE source_id = $1 AND target_id = actor_profile.id
AND request_status = $3
) AS requested
FROM actor_profile
WHERE actor_profile.id = ANY($2)
",
&[&source_id, &target_ids, &FollowRequestStatus::Pending],
).await?;
let relationships = rows.iter()
.map(Relationship::try_from)
.collect::<Result<_, _>>()?;
Ok(relationships)
}
pub async fn get_relationship(
db_client: &impl GenericClient,
source_id: &Uuid,