proto_blue_api/generated/com/atproto/temp/
checkHandleAvailability.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub birth_date: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub email: Option<String>,
15 pub handle: String,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(rename_all = "camelCase")]
20pub struct Output {
21 pub handle: String,
22 pub result: serde_json::Value,
23}
24
25#[derive(Debug, thiserror::Error)]
27pub enum CallError {
28 #[error("InvalidEmail")]
30 InvalidEmail,
31 #[error("{0}")]
32 Xrpc(proto_blue_xrpc::XrpcError),
33 #[error(transparent)]
34 Transport(#[from] proto_blue_xrpc::Error),
35 #[error(transparent)]
36 Json(#[from] serde_json::Error),
37}
38
39fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
40 match err.error.as_deref() {
41 Some("InvalidEmail") => CallError::InvalidEmail,
42 _ => CallError::Xrpc(err),
43 }
44}
45
46fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
47 let mut qp = proto_blue_xrpc::QueryParams::new();
48 if let Some(v) = &p.birth_date { qp.insert("birthDate".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
49 if let Some(v) = &p.email { qp.insert("email".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
50 { let v = &p.handle; qp.insert("handle".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
51 qp
52}
53
54pub async fn call(
56 client: &proto_blue_xrpc::XrpcClient,
57 params: Option<&Params>,
58 opts: Option<&proto_blue_xrpc::CallOptions>,
59) -> Result<Output, CallError> {
60 let qp = params.map(to_query_params);
61 let response = match client.query("com.atproto.temp.checkHandleAvailability", qp.as_ref(), opts).await {
62 Ok(r) => r,
63 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
64 Err(e) => return Err(CallError::Transport(e)),
65 };
66 Ok(serde_json::from_value(response.data)?)
67}
68
69#[cfg(feature = "server")]
71pub fn register<F, Fut>(
72server: proto_blue_xrpc::XrpcServer,
73handler: F,
74) -> proto_blue_xrpc::XrpcServer
75where
76 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
77 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
78{
79 let handler = std::sync::Arc::new(handler);
80 server.query("com.atproto.temp.checkHandleAvailability", move |ctx| {
81 let handler = handler.clone();
82 async move {
83 let params = params_from_ctx(&ctx);
84 let out = handler(ctx, params).await?;
85 let value = serde_json::to_value(&out)
86 .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
87 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
88 }
89 })
90}
91
92#[cfg(feature = "server")]
93fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
94 Some(Params {
98 birth_date: ctx.params.get("birthDate").cloned(),
99 email: ctx.params.get("email").cloned(),
100 handle: (ctx.params.get("handle").cloned())?,
101 })
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(rename_all = "camelCase")]
107pub struct ResultAvailable {
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(rename_all = "camelCase")]
113pub struct ResultUnavailable {
114 pub suggestions: Vec<Suggestion>,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(rename_all = "camelCase")]
119pub struct Suggestion {
120 pub handle: String,
121 pub method: String,
122}
123