proto_blue_api/generated/com/atproto/moderation/
createReport.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub mod_tool: Option<ModTool>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub reason: Option<String>,
15 pub reason_type: crate::com::atproto::moderation::defs::ReasonType,
16 pub subject: serde_json::Value,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct Output {
22 pub created_at: String,
23 pub id: i64,
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub reason: Option<String>,
26 pub reason_type: crate::com::atproto::moderation::defs::ReasonType,
27 pub reported_by: String,
28 pub subject: serde_json::Value,
29}
30
31#[derive(Debug, thiserror::Error)]
33pub enum CallError {
34 #[error("{0}")]
35 Xrpc(proto_blue_xrpc::XrpcError),
36 #[error(transparent)]
37 Transport(#[from] proto_blue_xrpc::Error),
38 #[error(transparent)]
39 Json(#[from] serde_json::Error),
40}
41
42fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
43 CallError::Xrpc(err)
44}
45
46pub async fn call(
48 client: &proto_blue_xrpc::XrpcClient,
49 input: &Input,
50 opts: Option<&proto_blue_xrpc::CallOptions>,
51) -> Result<Output, CallError> {
52 let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
53 let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
54 let response = match client.procedure("com.atproto.moderation.createReport", qp_ref, Some(body), opts).await {
55 Ok(r) => r,
56 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
57 Err(e) => return Err(CallError::Transport(e)),
58 };
59 Ok(serde_json::from_value(response.data)?)
60}
61
62#[cfg(feature = "server")]
64pub fn register<F, Fut>(
65server: proto_blue_xrpc::XrpcServer,
66handler: F,
67) -> proto_blue_xrpc::XrpcServer
68where
69 F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
70 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
71{
72 let handler = std::sync::Arc::new(handler);
73 server.procedure("com.atproto.moderation.createReport", move |ctx| {
74 let handler = handler.clone();
75 async move {
76 let input = match ctx.json_body()? {
77 Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
78 None => None,
79 };
80 let out = handler(ctx, input).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#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(rename_all = "camelCase")]
91pub struct ModTool {
92 #[serde(skip_serializing_if = "Option::is_none")]
93 pub meta: Option<serde_json::Value>,
94 pub name: String,
95}
96