Add API method for searching profiles by DID
This commit is contained in:
parent
21df4fa35c
commit
acb139b0ee
3 changed files with 59 additions and 13 deletions
|
@ -196,6 +196,28 @@ paths:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Relationship'
|
$ref: '#/components/schemas/Relationship'
|
||||||
|
/api/v1/accounts/search_did:
|
||||||
|
get:
|
||||||
|
summary: Search profile by DID
|
||||||
|
parameters:
|
||||||
|
- name: did
|
||||||
|
in: query
|
||||||
|
description: Decentralized identifier (DID)
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
description: Profile list
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Account'
|
||||||
|
400:
|
||||||
|
description: Invalid DID
|
||||||
/api/v1/accounts/{account_id}:
|
/api/v1/accounts/{account_id}:
|
||||||
get:
|
get:
|
||||||
summary: View information about a profile.
|
summary: View information about a profile.
|
||||||
|
|
|
@ -293,6 +293,11 @@ impl Default for RelationshipMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct SearchDidQueryParams {
|
||||||
|
pub did: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct FollowData {
|
pub struct FollowData {
|
||||||
#[serde(default = "default_showing_reblogs")]
|
#[serde(default = "default_showing_reblogs")]
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::mastodon_api::statuses::types::Status;
|
||||||
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,
|
||||||
|
search_profile_by_did,
|
||||||
update_profile,
|
update_profile,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::types::{
|
use crate::models::profiles::types::{
|
||||||
|
@ -68,6 +69,7 @@ use super::types::{
|
||||||
IdentityClaim,
|
IdentityClaim,
|
||||||
IdentityProofData,
|
IdentityProofData,
|
||||||
RelationshipQueryParams,
|
RelationshipQueryParams,
|
||||||
|
SearchDidQueryParams,
|
||||||
StatusListQueryParams,
|
StatusListQueryParams,
|
||||||
SubscriptionQueryParams,
|
SubscriptionQueryParams,
|
||||||
};
|
};
|
||||||
|
@ -153,18 +155,6 @@ pub async fn create_account(
|
||||||
Ok(HttpResponse::Created().json(account))
|
Ok(HttpResponse::Created().json(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/{account_id}")]
|
|
||||||
async fn get_account(
|
|
||||||
config: web::Data<Config>,
|
|
||||||
db_pool: web::Data<Pool>,
|
|
||||||
account_id: web::Path<Uuid>,
|
|
||||||
) -> Result<HttpResponse, HttpError> {
|
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
|
||||||
let profile = get_profile_by_id(db_client, &account_id).await?;
|
|
||||||
let account = Account::from_profile(profile, &config.instance_url());
|
|
||||||
Ok(HttpResponse::Ok().json(account))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/verify_credentials")]
|
#[get("/verify_credentials")]
|
||||||
async fn verify_credentials(
|
async fn verify_credentials(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -365,6 +355,34 @@ async fn get_relationships_view(
|
||||||
Ok(HttpResponse::Ok().json(vec![relationship]))
|
Ok(HttpResponse::Ok().json(vec![relationship]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/search_did")]
|
||||||
|
async fn search_by_did(
|
||||||
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
|
query_params: web::Query<SearchDidQueryParams>,
|
||||||
|
) -> Result<HttpResponse, HttpError> {
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let did: DidPkh = query_params.did.parse()
|
||||||
|
.map_err(|_| ValidationError("invalid DID"))?;
|
||||||
|
let profiles = search_profile_by_did(db_client, &did, false).await?;
|
||||||
|
let accounts: Vec<Account> = profiles.into_iter()
|
||||||
|
.map(|profile| Account::from_profile(profile, &config.instance_url()))
|
||||||
|
.collect();
|
||||||
|
Ok(HttpResponse::Ok().json(accounts))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/{account_id}")]
|
||||||
|
async fn get_account(
|
||||||
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
|
account_id: web::Path<Uuid>,
|
||||||
|
) -> Result<HttpResponse, HttpError> {
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let profile = get_profile_by_id(db_client, &account_id).await?;
|
||||||
|
let account = Account::from_profile(profile, &config.instance_url());
|
||||||
|
Ok(HttpResponse::Ok().json(account))
|
||||||
|
}
|
||||||
|
|
||||||
#[post("/{account_id}/follow")]
|
#[post("/{account_id}/follow")]
|
||||||
async fn follow_account(
|
async fn follow_account(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -548,13 +566,14 @@ pub fn account_api_scope() -> Scope {
|
||||||
web::scope("/api/v1/accounts")
|
web::scope("/api/v1/accounts")
|
||||||
// Routes without account ID
|
// Routes without account ID
|
||||||
.service(create_account)
|
.service(create_account)
|
||||||
.service(get_relationships_view)
|
|
||||||
.service(verify_credentials)
|
.service(verify_credentials)
|
||||||
.service(update_credentials)
|
.service(update_credentials)
|
||||||
.service(get_identity_claim)
|
.service(get_identity_claim)
|
||||||
.service(create_identity_proof)
|
.service(create_identity_proof)
|
||||||
.service(authorize_subscription)
|
.service(authorize_subscription)
|
||||||
.service(subscriptions_enabled)
|
.service(subscriptions_enabled)
|
||||||
|
.service(get_relationships_view)
|
||||||
|
.service(search_by_did)
|
||||||
// Routes with account ID
|
// Routes with account ID
|
||||||
.service(get_account)
|
.service(get_account)
|
||||||
.service(follow_account)
|
.service(follow_account)
|
||||||
|
|
Loading…
Reference in a new issue