Skip to main content

proto_blue_api/generated/tools/ozone/verification/
listVerifications.rs

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