Skip to main content

proto_blue_api/generated/tools/ozone/moderation/
getRepo.rs

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