proto_blue_api/generated/com/atproto/temp/
fetchLabels.rs1#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Params {
12 #[serde(skip_serializing_if = "Option::is_none")]
13 pub limit: Option<i64>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub since: Option<i64>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(rename_all = "camelCase")]
20pub struct Output {
21 pub labels: Vec<crate::com::atproto::label::defs::Label>,
22}
23
24#[derive(Debug, thiserror::Error)]
26pub enum CallError {
27 #[error("{0}")]
28 Xrpc(proto_blue_xrpc::XrpcError),
29 #[error(transparent)]
30 Transport(#[from] proto_blue_xrpc::Error),
31 #[error(transparent)]
32 Json(#[from] serde_json::Error),
33}
34
35fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
36 CallError::Xrpc(err)
37}
38
39fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
40 let mut qp = proto_blue_xrpc::QueryParams::new();
41 if let Some(v) = &p.limit {
42 qp.insert(
43 "limit".to_string(),
44 proto_blue_xrpc::QueryValue::Integer(*v),
45 );
46 }
47 if let Some(v) = &p.since {
48 qp.insert(
49 "since".to_string(),
50 proto_blue_xrpc::QueryValue::Integer(*v),
51 );
52 }
53 qp
54}
55
56pub async fn call(
58 client: &proto_blue_xrpc::XrpcClient,
59 params: Option<&Params>,
60 opts: Option<&proto_blue_xrpc::CallOptions>,
61) -> Result<Output, CallError> {
62 let qp = params.map(to_query_params);
63 let response = match client
64 .query("com.atproto.temp.fetchLabels", qp.as_ref(), opts)
65 .await
66 {
67 Ok(r) => r,
68 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
69 Err(e) => return Err(CallError::Transport(e)),
70 };
71 Ok(serde_json::from_value(response.data)?)
72}
73
74#[cfg(feature = "server")]
76pub fn register<F, Fut>(
77 server: proto_blue_xrpc::XrpcServer,
78 handler: F,
79) -> proto_blue_xrpc::XrpcServer
80where
81 F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
82 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
83 + Send
84 + 'static,
85{
86 let handler = std::sync::Arc::new(handler);
87 server.query("com.atproto.temp.fetchLabels", move |ctx| {
88 let handler = handler.clone();
89 async move {
90 let params = params_from_ctx(&ctx);
91 let out = handler(ctx, params).await?;
92 let value = serde_json::to_value(&out).map_err(|e| {
93 proto_blue_xrpc::XrpcServerError::new(
94 proto_blue_xrpc::ResponseType::InternalServerError,
95 format!("output serialize: {e}"),
96 )
97 })?;
98 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
99 }
100 })
101}
102
103#[cfg(feature = "server")]
104fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
105 Some(Params {
109 limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
110 since: ctx.params.get("since").and_then(|v| v.parse::<i64>().ok()),
111 })
112}