Skip to main content

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

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.admin.disableInviteCodes
3
4use serde::{Deserialize, Serialize};
5
6/// Disable some set of codes and/or all codes associated with a set of users.
7/// XRPC Procedure: com.atproto.admin.disableInviteCodes
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub accounts: Option<Vec<String>>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub codes: Option<Vec<String>>,
15}
16
17/// Errors a `call()` on this method can return.
18#[derive(Debug, thiserror::Error)]
19pub enum CallError {
20    #[error("{0}")]
21    Xrpc(proto_blue_xrpc::XrpcError),
22    #[error(transparent)]
23    Transport(#[from] proto_blue_xrpc::Error),
24    #[error(transparent)]
25    Json(#[from] serde_json::Error),
26}
27
28fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
29    CallError::Xrpc(err)
30}
31
32/// Execute the procedure.
33pub async fn call(
34    client: &proto_blue_xrpc::XrpcClient,
35    input: &Input,
36    opts: Option<&proto_blue_xrpc::CallOptions>,
37) -> Result<serde_json::Value, CallError> {
38    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
39    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
40    let response = match client.procedure("com.atproto.admin.disableInviteCodes", qp_ref, Some(body), opts).await {
41        Ok(r) => r,
42        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
43        Err(e) => return Err(CallError::Transport(e)),
44    };
45    Ok(response.data)
46}
47
48/// Register a typed handler for this procedure on an [`XrpcServer`].
49#[cfg(feature = "server")]
50pub fn register<F, Fut>(
51server: proto_blue_xrpc::XrpcServer,
52handler: F,
53) -> proto_blue_xrpc::XrpcServer
54where
55    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
56    Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
57{
58    let handler = std::sync::Arc::new(handler);
59    server.procedure("com.atproto.admin.disableInviteCodes", move |ctx| {
60        let handler = handler.clone();
61        async move {
62            let input = match ctx.json_body()? {
63                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
64                None => None,
65            };
66            let out = handler(ctx, input).await?;
67            Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
68        }
69    })
70}
71