Add wallet address to data returned by /api/v1/accounts/{account_id} method
This commit is contained in:
parent
20a7e127c7
commit
464d4886fa
3 changed files with 36 additions and 1 deletions
|
@ -108,6 +108,20 @@ paths:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Relationship'
|
$ref: '#/components/schemas/Relationship'
|
||||||
|
/api/v1/accounts/{account_id}:
|
||||||
|
get:
|
||||||
|
summary: View information about a profile.
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/account_id'
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Account'
|
||||||
|
404:
|
||||||
|
description: Profile not found
|
||||||
/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.
|
||||||
|
|
|
@ -24,6 +24,7 @@ use crate::mastodon_api::timelines::types::TimelineQueryParams;
|
||||||
use crate::models::posts::queries::get_posts_by_author;
|
use crate::models::posts::queries::get_posts_by_author;
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
get_profile_by_id,
|
get_profile_by_id,
|
||||||
|
get_wallet_address,
|
||||||
update_profile,
|
update_profile,
|
||||||
};
|
};
|
||||||
use crate::models::relationships::queries::{
|
use crate::models::relationships::queries::{
|
||||||
|
@ -103,7 +104,9 @@ async fn get_account(
|
||||||
) -> 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 profile = get_profile_by_id(db_client, &account_id).await?;
|
let profile = get_profile_by_id(db_client, &account_id).await?;
|
||||||
let account = Account::from_profile(profile, &config.instance_url());
|
let maybe_wallet_address = get_wallet_address(db_client, &profile.id).await?;
|
||||||
|
let mut account = Account::from_profile(profile, &config.instance_url());
|
||||||
|
account.wallet_address = maybe_wallet_address;
|
||||||
Ok(HttpResponse::Ok().json(account))
|
Ok(HttpResponse::Ok().json(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -357,6 +357,24 @@ pub async fn search_profile_by_wallet_address(
|
||||||
Ok(profiles)
|
Ok(profiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_wallet_address(
|
||||||
|
db_client: &impl GenericClient,
|
||||||
|
profile_id: &Uuid,
|
||||||
|
) -> Result<Option<String>, DatabaseError> {
|
||||||
|
let maybe_row = db_client.query_opt(
|
||||||
|
"
|
||||||
|
SELECT user_account.wallet_address
|
||||||
|
FROM actor_profile
|
||||||
|
LEFT JOIN user_account ON (actor_profile.id = user_account.id)
|
||||||
|
WHERE actor_profile.id = $1
|
||||||
|
",
|
||||||
|
&[&profile_id],
|
||||||
|
).await?;
|
||||||
|
let row = maybe_row.ok_or(DatabaseError::NotFound("profile"))?;
|
||||||
|
let wallet_address = row.try_get("wallet_address")?;
|
||||||
|
Ok(wallet_address)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_follower_count(
|
pub async fn update_follower_count(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
profile_id: &Uuid,
|
profile_id: &Uuid,
|
||||||
|
|
Loading…
Reference in a new issue