Skip to main content

proto_blue_api/generated/com/atproto/temp/
fetchLabels.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.temp.fetchLabels
3
4use serde::{Deserialize, Serialize};
5
6/// DEPRECATED: use queryLabels or subscribeLabels instead -- Fetch all labels from a labeler created after a certain date.
7/// XRPC Query: com.atproto.temp.fetchLabels
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub limit: Option<i64>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub since: Option<i64>,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct Output {
20    pub labels: Vec<crate::com::atproto::label::defs::Label>,
21}
22
23/// Errors a `call()` on this method can return.
24#[derive(Debug, thiserror::Error)]
25pub enum CallError {
26    #[error("{0}")]
27    Xrpc(proto_blue_xrpc::XrpcError),
28    #[error(transparent)]
29    Transport(#[from] proto_blue_xrpc::Error),
30    #[error(transparent)]
31    Json(#[from] serde_json::Error),
32}
33
34fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
35    CallError::Xrpc(err)
36}
37
38fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
39    let mut qp = proto_blue_xrpc::QueryParams::new();
40    if let Some(v) = &p.limit { qp.insert("limit".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
41    if let Some(v) = &p.since { qp.insert("since".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
42    qp
43}
44
45/// Execute the query.
46pub async fn call(
47    client: &proto_blue_xrpc::XrpcClient,
48    params: Option<&Params>,
49    opts: Option<&proto_blue_xrpc::CallOptions>,
50) -> Result<Output, CallError> {
51    let qp = params.map(to_query_params);
52    let response = match client.query("com.atproto.temp.fetchLabels", qp.as_ref(), opts).await {
53        Ok(r) => r,
54        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
55        Err(e) => return Err(CallError::Transport(e)),
56    };
57    Ok(serde_json::from_value(response.data)?)
58}
59
60/// Register a typed handler for this method on an [`XrpcServer`].
61#[cfg(feature = "server")]
62pub fn register<F, Fut>(
63server: proto_blue_xrpc::XrpcServer,
64handler: F,
65) -> proto_blue_xrpc::XrpcServer
66where
67    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
68    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
69{
70    let handler = std::sync::Arc::new(handler);
71    server.query("com.atproto.temp.fetchLabels", move |ctx| {
72        let handler = handler.clone();
73        async move {
74            let params = params_from_ctx(&ctx);
75            let out = handler(ctx, params).await?;
76            let value = serde_json::to_value(&out)
77                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
78            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
79        }
80    })
81}
82
83#[cfg(feature = "server")]
84fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
85    // Always construct a `Params` — required fields are
86    // validated upstream by the lexicon validator when enabled;
87    // missing values surface as runtime errors from the handler.
88    Some(Params {
89        limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
90        since: ctx.params.get("since").and_then(|v| v.parse::<i64>().ok()),
91    })
92}
93