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