Skip to main content

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

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: tools.ozone.moderation.queryEvents
3
4use serde::{Deserialize, Serialize};
5
6/// List moderation events related to a subject.
7/// XRPC Query: tools.ozone.moderation.queryEvents
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Params {
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub added_labels: Option<Vec<String>>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub added_tags: Option<Vec<String>>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub age_assurance_state: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub batch_id: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub collections: Option<Vec<String>>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub comment: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub created_after: Option<String>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub created_before: Option<String>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub created_by: Option<String>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub cursor: Option<String>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub has_comment: Option<bool>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub include_all_user_records: Option<bool>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub limit: Option<i64>,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub mod_tool: Option<Vec<String>>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub policies: Option<Vec<String>>,
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub removed_labels: Option<Vec<String>>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub removed_tags: Option<Vec<String>>,
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub report_types: Option<Vec<String>>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub sort_direction: Option<String>,
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub subject: Option<String>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub subject_type: Option<String>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub types: Option<Vec<String>>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub with_strike: Option<bool>,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(rename_all = "camelCase")]
61pub struct Output {
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub cursor: Option<String>,
64    pub events: Vec<crate::tools::ozone::moderation::defs::ModEventView>,
65}
66
67/// Errors a `call()` on this method can return.
68#[derive(Debug, thiserror::Error)]
69pub enum CallError {
70    #[error("{0}")]
71    Xrpc(proto_blue_xrpc::XrpcError),
72    #[error(transparent)]
73    Transport(#[from] proto_blue_xrpc::Error),
74    #[error(transparent)]
75    Json(#[from] serde_json::Error),
76}
77
78fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
79    CallError::Xrpc(err)
80}
81
82fn to_query_params(p: &Params) -> proto_blue_xrpc::QueryParams {
83    let mut qp = proto_blue_xrpc::QueryParams::new();
84    if let Some(v) = &p.added_labels { qp.insert("addedLabels".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
85    if let Some(v) = &p.added_tags { qp.insert("addedTags".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
86    if let Some(v) = &p.age_assurance_state { qp.insert("ageAssuranceState".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
87    if let Some(v) = &p.batch_id { qp.insert("batchId".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
88    if let Some(v) = &p.collections { qp.insert("collections".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
89    if let Some(v) = &p.comment { qp.insert("comment".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
90    if let Some(v) = &p.created_after { qp.insert("createdAfter".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
91    if let Some(v) = &p.created_before { qp.insert("createdBefore".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
92    if let Some(v) = &p.created_by { qp.insert("createdBy".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
93    if let Some(v) = &p.cursor { qp.insert("cursor".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
94    if let Some(v) = &p.has_comment { qp.insert("hasComment".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
95    if let Some(v) = &p.include_all_user_records { qp.insert("includeAllUserRecords".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
96    if let Some(v) = &p.limit { qp.insert("limit".to_string(), proto_blue_xrpc::QueryValue::Integer(*v)); }
97    if let Some(v) = &p.mod_tool { qp.insert("modTool".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
98    if let Some(v) = &p.policies { qp.insert("policies".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
99    if let Some(v) = &p.removed_labels { qp.insert("removedLabels".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
100    if let Some(v) = &p.removed_tags { qp.insert("removedTags".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
101    if let Some(v) = &p.report_types { qp.insert("reportTypes".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
102    if let Some(v) = &p.sort_direction { qp.insert("sortDirection".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
103    if let Some(v) = &p.subject { qp.insert("subject".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
104    if let Some(v) = &p.subject_type { qp.insert("subjectType".to_string(), proto_blue_xrpc::QueryValue::String(v.clone())); }
105    if let Some(v) = &p.types { qp.insert("types".to_string(), proto_blue_xrpc::QueryValue::Array(v.iter().map(|x| proto_blue_xrpc::QueryValue::String(x.clone())).collect())); }
106    if let Some(v) = &p.with_strike { qp.insert("withStrike".to_string(), proto_blue_xrpc::QueryValue::Boolean(*v)); }
107    qp
108}
109
110/// Execute the query.
111pub async fn call(
112    client: &proto_blue_xrpc::XrpcClient,
113    params: Option<&Params>,
114    opts: Option<&proto_blue_xrpc::CallOptions>,
115) -> Result<Output, CallError> {
116    let qp = params.map(to_query_params);
117    let response = match client.query("tools.ozone.moderation.queryEvents", qp.as_ref(), opts).await {
118        Ok(r) => r,
119        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
120        Err(e) => return Err(CallError::Transport(e)),
121    };
122    Ok(serde_json::from_value(response.data)?)
123}
124
125/// Register a typed handler for this method on an [`XrpcServer`].
126#[cfg(feature = "server")]
127pub fn register<F, Fut>(
128server: proto_blue_xrpc::XrpcServer,
129handler: F,
130) -> proto_blue_xrpc::XrpcServer
131where
132    F: Fn(proto_blue_xrpc::HandlerContext, Option<Params>) -> Fut + Send + Sync + 'static,
133    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
134{
135    let handler = std::sync::Arc::new(handler);
136    server.query("tools.ozone.moderation.queryEvents", move |ctx| {
137        let handler = handler.clone();
138        async move {
139            let params = params_from_ctx(&ctx);
140            let out = handler(ctx, params).await?;
141            let value = serde_json::to_value(&out)
142                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
143            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
144        }
145    })
146}
147
148#[cfg(feature = "server")]
149fn params_from_ctx(ctx: &proto_blue_xrpc::HandlerContext) -> Option<Params> {
150    // Always construct a `Params` — required fields are
151    // validated upstream by the lexicon validator when enabled;
152    // missing values surface as runtime errors from the handler.
153    Some(Params {
154        added_labels: Some(ctx.params.get("addedLabels").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
155        added_tags: Some(ctx.params.get("addedTags").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
156        age_assurance_state: ctx.params.get("ageAssuranceState").cloned(),
157        batch_id: ctx.params.get("batchId").cloned(),
158        collections: Some(ctx.params.get("collections").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
159        comment: ctx.params.get("comment").cloned(),
160        created_after: ctx.params.get("createdAfter").cloned(),
161        created_before: ctx.params.get("createdBefore").cloned(),
162        created_by: ctx.params.get("createdBy").cloned(),
163        cursor: ctx.params.get("cursor").cloned(),
164        has_comment: ctx.params.get("hasComment").and_then(|v| v.parse::<bool>().ok()),
165        include_all_user_records: ctx.params.get("includeAllUserRecords").and_then(|v| v.parse::<bool>().ok()),
166        limit: ctx.params.get("limit").and_then(|v| v.parse::<i64>().ok()),
167        mod_tool: Some(ctx.params.get("modTool").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
168        policies: Some(ctx.params.get("policies").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
169        removed_labels: Some(ctx.params.get("removedLabels").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
170        removed_tags: Some(ctx.params.get("removedTags").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
171        report_types: Some(ctx.params.get("reportTypes").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
172        sort_direction: ctx.params.get("sortDirection").cloned(),
173        subject: ctx.params.get("subject").cloned(),
174        subject_type: ctx.params.get("subjectType").cloned(),
175        types: Some(ctx.params.get("types").map(|v| v.split(',').map(String::from).collect::<Vec<_>>()).unwrap_or_default()),
176        with_strike: ctx.params.get("withStrike").and_then(|v| v.parse::<bool>().ok()),
177    })
178}
179