Something went wrong. Try again.
A downstream fork of Tranquil PDS for use in margin.cafe
Something went wrong. Try again.
Rust
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455use axum::{Json, extract::State};use serde::Deserialize;use tracing::warn;use tranquil_pds::api::EmptyResponse;use tranquil_pds::api::error::{ApiError, DbResultExt};use tranquil_pds::auth::{Admin, Auth};use tranquil_pds::state::AppState;use tranquil_pds::types::Did;
#[derive(Deserialize)]pub struct DeleteAccountInput { pub did: Did,}
pub async fn delete_account( State(state): State<AppState>, _auth: Auth<Admin>, Json(input): Json<DeleteAccountInput>,) -> Result<Json<EmptyResponse>, ApiError> { let did = &input.did; let (user_id, handle) = state .repos .user .get_id_and_handle_by_did(did) .await .log_db_err("in delete_account")? .ok_or(ApiError::AccountNotFound) .map(|row| (row.id, row.handle))?;
state .repos .user .admin_delete_account_complete(user_id, did) .await .log_db_err("deleting account")?;
if let Err(e) = tranquil_pds::repo_ops::sequence_account_event( &state, did, tranquil_db_traits::AccountStatus::Deleted, ) .await { warn!( "Failed to sequence account deletion event for {}: {}", did, e ); } let _ = state .cache .delete(&tranquil_pds::cache_keys::handle_key(&handle)) .await; Ok(Json(EmptyResponse {}))}