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
41        .procedure(
42            "com.atproto.admin.disableInviteCodes",
43            qp_ref,
44            Some(body),
45            opts,
46        )
47        .await
48    {
49        Ok(r) => r,
50        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
51        Err(e) => return Err(CallError::Transport(e)),
52    };
53    Ok(response.data)
54}
55
56/// Register a typed handler for this procedure on an [`proto_blue_xrpc::XrpcServer`].
57#[cfg(feature = "server")]
58pub fn register<F, Fut>(
59    server: proto_blue_xrpc::XrpcServer,
60    handler: F,
61) -> proto_blue_xrpc::XrpcServer
62where
63    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
64    Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>>
65        + Send
66        + 'static,
67{
68    let handler = std::sync::Arc::new(handler);
69    server.procedure("com.atproto.admin.disableInviteCodes", move |ctx| {
70        let handler = handler.clone();
71        async move {
72            let input = match ctx.json_body()? {
73                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
74                    proto_blue_xrpc::XrpcServerError::new(
75                        proto_blue_xrpc::ResponseType::InvalidRequest,
76                        format!("input deserialize: {e}"),
77                    )
78                })?),
79                None => None,
80            };
81            let out = handler(ctx, input).await?;
82            Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
83        }
84    })
85}