uarp_sdk/generated/api/
reports.rs1#![allow(unused_imports, clippy::too_many_arguments)]
7
8use reqwest::Method;
9use serde::{Deserialize, Serialize};
10use futures_core::Stream;
11
12use crate::client::{Client, Request, NO_BODY, NO_QUERY};
13use crate::error::Result;
14use crate::generated::models;
15use crate::multipart::{field_text, FilePart};
16use crate::pagination::CursorGuard;
17use crate::util::encode_path;
18
19#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
21pub struct ListAllContentReportsParams {
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub limit: Option<i64>,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
25 pub cursor: Option<String>,
26}
27
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
30pub struct ListContentReportsParams {
31 #[serde(default, skip_serializing_if = "Option::is_none")]
32 pub limit: Option<i64>,
33 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub cursor: Option<String>,
35}
36
37#[derive(Debug, Clone)]
40pub struct ReportsApi {
41 pub(crate) client: Client,
42}
43
44impl Client {
45 pub fn reports(&self) -> ReportsApi {
48 ReportsApi { client: self.clone() }
49 }
50}
51
52impl ReportsApi {
53 pub async fn create_content_report(&self, body: &models::ContentReportInput) -> Result<models::ContentReportAccepted> {
62 self.client
63 .request_json(Request {
64 method: Method::POST,
65 path: "/api/v1/reports".to_string(),
66 query: NO_QUERY,
67 body: Some(body),
68 headers: Vec::new(),
69 idempotent: true,
70 })
71 .await
72 }
73
74 pub async fn list_all_content_reports(&self, params: &ListAllContentReportsParams) -> Result<models::ListAllContentReportsResponse> {
83 self.client
84 .request_json(Request {
85 method: Method::GET,
86 path: "/api/v1/admin/reports".to_string(),
87 query: Some(params),
88 body: NO_BODY,
89 headers: Vec::new(),
90 idempotent: false,
91 })
92 .await
93 }
94
95 pub fn list_all_content_reports_all<'a>(&'a self, params: &'a ListAllContentReportsParams) -> impl Stream<Item = Result<models::ContentReport>> + 'a {
98 async_stream::try_stream! {
99 let mut guard = CursorGuard::new();
100 let mut cursor = params.cursor.clone();
101 loop {
102 let mut page_params = params.clone();
103 page_params.cursor = cursor.clone();
104 let page = self.list_all_content_reports(&page_params).await?;
105 let items = page.items;
106 let was_empty = items.is_empty();
107 for item in items {
108 yield item;
109 }
110 match guard.advance(page.cursor, Some(page.has_more), was_empty) {
111 Some(next) => cursor = Some(next),
112 None => break,
113 }
114 }
115 }
116 }
117
118 pub async fn list_content_reports(&self, params: &ListContentReportsParams) -> Result<models::ListContentReportsResponse> {
125 self.client
126 .request_json(Request {
127 method: Method::GET,
128 path: "/api/v1/reports".to_string(),
129 query: Some(params),
130 body: NO_BODY,
131 headers: Vec::new(),
132 idempotent: false,
133 })
134 .await
135 }
136
137 pub fn list_content_reports_all<'a>(&'a self, params: &'a ListContentReportsParams) -> impl Stream<Item = Result<models::ContentReport>> + 'a {
140 async_stream::try_stream! {
141 let mut guard = CursorGuard::new();
142 let mut cursor = params.cursor.clone();
143 loop {
144 let mut page_params = params.clone();
145 page_params.cursor = cursor.clone();
146 let page = self.list_content_reports(&page_params).await?;
147 let items = page.items;
148 let was_empty = items.is_empty();
149 for item in items {
150 yield item;
151 }
152 match guard.advance(page.cursor, Some(page.has_more), was_empty) {
153 Some(next) => cursor = Some(next),
154 None => break,
155 }
156 }
157 }
158 }
159}