Remove get_relationships function and use get_relationship instead
This commit is contained in:
parent
548e000b3e
commit
a81d0ef216
3 changed files with 26 additions and 39 deletions
|
@ -87,6 +87,27 @@ paths:
|
||||||
$ref: '#/components/schemas/Account'
|
$ref: '#/components/schemas/Account'
|
||||||
400:
|
400:
|
||||||
description: Invalid user data
|
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:
|
/api/v1/accounts/{account_id}/statuses:
|
||||||
get:
|
get:
|
||||||
summary: Posts created by the given actor.
|
summary: Posts created by the given actor.
|
||||||
|
@ -601,7 +622,7 @@ components:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
description: The account id.
|
description: Target profile id.
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
following:
|
following:
|
||||||
|
|
|
@ -33,7 +33,6 @@ use crate::models::relationships::queries::{
|
||||||
get_followers,
|
get_followers,
|
||||||
get_following,
|
get_following,
|
||||||
get_relationship,
|
get_relationship,
|
||||||
get_relationships,
|
|
||||||
unfollow,
|
unfollow,
|
||||||
};
|
};
|
||||||
use crate::models::users::queries::{
|
use crate::models::users::queries::{
|
||||||
|
@ -185,12 +184,12 @@ async fn get_relationships_view(
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||||
let relationships = get_relationships(
|
let relationship = get_relationship(
|
||||||
db_client,
|
db_client,
|
||||||
current_user.id,
|
¤t_user.id,
|
||||||
vec![query_params.into_inner().id],
|
&query_params.id,
|
||||||
).await?;
|
).await?;
|
||||||
Ok(HttpResponse::Ok().json(relationships))
|
Ok(HttpResponse::Ok().json(vec![relationship]))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/{account_id}/follow")]
|
#[post("/{account_id}/follow")]
|
||||||
|
|
|
@ -18,39 +18,6 @@ use super::types::{
|
||||||
Relationship,
|
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(
|
pub async fn get_relationship(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
source_id: &Uuid,
|
source_id: &Uuid,
|
||||||
|
|
Loading…
Reference in a new issue