proto_blue_api/generated/com/atproto/moderation/
createReport.rs1#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(tag = "$type")]
11pub enum InputSubjectRefs {
12 #[serde(rename = "com.atproto.admin.defs#repoRef")]
13 AtprotoAdminDefsRepoRef(Box<crate::com::atproto::admin::defs::RepoRef>),
14 #[serde(rename = "com.atproto.repo.strongRef")]
15 AtprotoRepoStrongRef(Box<crate::com::atproto::repo::strong_ref::Main>),
16 #[serde(other)]
17 Other,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct Input {
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub mod_tool: Option<ModTool>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub reason: Option<String>,
27 pub reason_type: crate::com::atproto::moderation::defs::ReasonType,
28 pub subject: InputSubjectRefs,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(tag = "$type")]
33pub enum OutputSubjectRefs {
34 #[serde(rename = "com.atproto.admin.defs#repoRef")]
35 AtprotoAdminDefsRepoRef(Box<crate::com::atproto::admin::defs::RepoRef>),
36 #[serde(rename = "com.atproto.repo.strongRef")]
37 AtprotoRepoStrongRef(Box<crate::com::atproto::repo::strong_ref::Main>),
38 #[serde(other)]
39 Other,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct Output {
45 pub created_at: proto_blue_syntax::Datetime,
46 pub id: i64,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub reason: Option<String>,
49 pub reason_type: crate::com::atproto::moderation::defs::ReasonType,
50 pub reported_by: proto_blue_syntax::Did,
51 pub subject: OutputSubjectRefs,
52}
53
54#[derive(Debug, thiserror::Error)]
56pub enum CallError {
57 #[error("{0}")]
58 Xrpc(proto_blue_xrpc::XrpcError),
59 #[error(transparent)]
60 Transport(#[from] proto_blue_xrpc::Error),
61 #[error(transparent)]
62 Json(#[from] serde_json::Error),
63}
64
65fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
66 CallError::Xrpc(err)
67}
68
69pub async fn call(
71 client: &proto_blue_xrpc::XrpcClient,
72 input: &Input,
73 opts: Option<&proto_blue_xrpc::CallOptions>,
74) -> Result<Output, CallError> {
75 let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
76 let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
77 let response = match client
78 .procedure(
79 "com.atproto.moderation.createReport",
80 qp_ref,
81 Some(body),
82 opts,
83 )
84 .await
85 {
86 Ok(r) => r,
87 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
88 Err(e) => return Err(CallError::Transport(e)),
89 };
90 Ok(serde_json::from_value(response.data)?)
91}
92
93#[cfg(feature = "server")]
95pub fn register<F, Fut>(
96 server: proto_blue_xrpc::XrpcServer,
97 handler: F,
98) -> proto_blue_xrpc::XrpcServer
99where
100 F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
101 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
102 + Send
103 + 'static,
104{
105 let handler = std::sync::Arc::new(handler);
106 server.procedure("com.atproto.moderation.createReport", move |ctx| {
107 let handler = handler.clone();
108 async move {
109 let input = match ctx.json_body()? {
110 Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
111 proto_blue_xrpc::XrpcServerError::new(
112 proto_blue_xrpc::ResponseType::InvalidRequest,
113 format!("input deserialize: {e}"),
114 )
115 })?),
116 None => None,
117 };
118 let out = handler(ctx, input).await?;
119 let value = serde_json::to_value(&out).map_err(|e| {
120 proto_blue_xrpc::XrpcServerError::new(
121 proto_blue_xrpc::ResponseType::InternalServerError,
122 format!("output serialize: {e}"),
123 )
124 })?;
125 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
126 }
127 })
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
132#[serde(rename_all = "camelCase")]
133pub struct ModTool {
134 #[serde(skip_serializing_if = "Option::is_none")]
135 pub meta: Option<serde_json::Value>,
136 pub name: String,
137}