Skip to main content

proto_blue_api/generated/com/atproto/admin/
updateSubjectStatus.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.admin.updateSubjectStatus
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7/// Update the service-specific admin status of a subject (account, record, or blob).
8/// XRPC Procedure: com.atproto.admin.updateSubjectStatus
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(tag = "$type")]
11pub enum InputSubjectRefs {
12    #[serde(rename = "com.atproto.admin.defs#repoRef")]
13    AtprotoAdminDefsRepoRef(Box<crate::com::atproto::admin::defs::RepoRef>),
14    #[serde(rename = "com.atproto.repo.strongRef")]
15    AtprotoRepoStrongRef(Box<crate::com::atproto::repo::strong_ref::Main>),
16    #[serde(rename = "com.atproto.admin.defs#repoBlobRef")]
17    AtprotoAdminDefsRepoBlobRef(Box<crate::com::atproto::admin::defs::RepoBlobRef>),
18    #[serde(other)]
19    Other,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct Input {
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub deactivated: Option<crate::com::atproto::admin::defs::StatusAttr>,
27    pub subject: InputSubjectRefs,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub takedown: Option<crate::com::atproto::admin::defs::StatusAttr>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(tag = "$type")]
34pub enum OutputSubjectRefs {
35    #[serde(rename = "com.atproto.admin.defs#repoRef")]
36    AtprotoAdminDefsRepoRef(Box<crate::com::atproto::admin::defs::RepoRef>),
37    #[serde(rename = "com.atproto.repo.strongRef")]
38    AtprotoRepoStrongRef(Box<crate::com::atproto::repo::strong_ref::Main>),
39    #[serde(rename = "com.atproto.admin.defs#repoBlobRef")]
40    AtprotoAdminDefsRepoBlobRef(Box<crate::com::atproto::admin::defs::RepoBlobRef>),
41    #[serde(other)]
42    Other,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct Output {
48    pub subject: OutputSubjectRefs,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub takedown: Option<crate::com::atproto::admin::defs::StatusAttr>,
51}
52
53/// Errors a `call()` on this method can return.
54#[derive(Debug, thiserror::Error)]
55pub enum CallError {
56    #[error("{0}")]
57    Xrpc(proto_blue_xrpc::XrpcError),
58    #[error(transparent)]
59    Transport(#[from] proto_blue_xrpc::Error),
60    #[error(transparent)]
61    Json(#[from] serde_json::Error),
62}
63
64fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
65    CallError::Xrpc(err)
66}
67
68/// Execute the procedure.
69pub async fn call(
70    client: &proto_blue_xrpc::XrpcClient,
71    input: &Input,
72    opts: Option<&proto_blue_xrpc::CallOptions>,
73) -> Result<Output, CallError> {
74    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
75    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
76    let response = match client
77        .procedure(
78            "com.atproto.admin.updateSubjectStatus",
79            qp_ref,
80            Some(body),
81            opts,
82        )
83        .await
84    {
85        Ok(r) => r,
86        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
87        Err(e) => return Err(CallError::Transport(e)),
88    };
89    Ok(serde_json::from_value(response.data)?)
90}
91
92/// Register a typed handler for this procedure on an [`proto_blue_xrpc::XrpcServer`].
93#[cfg(feature = "server")]
94pub fn register<F, Fut>(
95    server: proto_blue_xrpc::XrpcServer,
96    handler: F,
97) -> proto_blue_xrpc::XrpcServer
98where
99    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
100    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
101        + Send
102        + 'static,
103{
104    let handler = std::sync::Arc::new(handler);
105    server.procedure("com.atproto.admin.updateSubjectStatus", move |ctx| {
106        let handler = handler.clone();
107        async move {
108            let input = match ctx.json_body()? {
109                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
110                    proto_blue_xrpc::XrpcServerError::new(
111                        proto_blue_xrpc::ResponseType::InvalidRequest,
112                        format!("input deserialize: {e}"),
113                    )
114                })?),
115                None => None,
116            };
117            let out = handler(ctx, input).await?;
118            let value = serde_json::to_value(&out).map_err(|e| {
119                proto_blue_xrpc::XrpcServerError::new(
120                    proto_blue_xrpc::ResponseType::InternalServerError,
121                    format!("output serialize: {e}"),
122                )
123            })?;
124            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
125        }
126    })
127}