Skip to main content

proto_blue_api/generated/app/bsky/graph/
getList.rs

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