1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{AuthRequired, ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait FoldersApi: Send + Sync {
29 async fn delete<'a>(&self, id: &'a str) -> Result<(), Error<DeleteError>>;
31
32 async fn delete_all(&self) -> Result<(), Error<DeleteAllError>>;
34
35 async fn get<'a>(&self, id: &'a str) -> Result<models::FolderResponseModel, Error<GetError>>;
37
38 async fn get_all(
40 &self,
41 ) -> Result<models::FolderResponseModelListResponseModel, Error<GetAllError>>;
42
43 async fn post<'a>(
45 &self,
46 folder_request_model: Option<models::FolderRequestModel>,
47 ) -> Result<models::FolderResponseModel, Error<PostError>>;
48
49 async fn put<'a>(
51 &self,
52 id: &'a str,
53 folder_request_model: Option<models::FolderRequestModel>,
54 ) -> Result<models::FolderResponseModel, Error<PutError>>;
55}
56
57pub struct FoldersApiClient {
58 configuration: Arc<configuration::Configuration>,
59}
60
61impl FoldersApiClient {
62 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
63 Self { configuration }
64 }
65}
66
67#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
68#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
69impl FoldersApi for FoldersApiClient {
70 async fn delete<'a>(&self, id: &'a str) -> Result<(), Error<DeleteError>> {
71 let local_var_configuration = &self.configuration;
72
73 let local_var_client = &local_var_configuration.client;
74
75 let local_var_uri_str = format!(
76 "{}/folders/{id}",
77 local_var_configuration.base_path,
78 id = crate::apis::urlencode(id)
79 );
80 let mut local_var_req_builder =
81 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
82
83 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
84
85 let local_var_resp = local_var_req_builder.send().await?;
86
87 let local_var_status = local_var_resp.status();
88 let local_var_content = local_var_resp.text().await?;
89
90 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91 Ok(())
92 } else {
93 let local_var_entity: Option<DeleteError> =
94 serde_json::from_str(&local_var_content).ok();
95 let local_var_error = ResponseContent {
96 status: local_var_status,
97 content: local_var_content,
98 entity: local_var_entity,
99 };
100 Err(Error::ResponseError(local_var_error))
101 }
102 }
103
104 async fn delete_all(&self) -> Result<(), Error<DeleteAllError>> {
105 let local_var_configuration = &self.configuration;
106
107 let local_var_client = &local_var_configuration.client;
108
109 let local_var_uri_str = format!("{}/folders/all", local_var_configuration.base_path);
110 let mut local_var_req_builder =
111 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
112
113 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
114
115 let local_var_resp = local_var_req_builder.send().await?;
116
117 let local_var_status = local_var_resp.status();
118 let local_var_content = local_var_resp.text().await?;
119
120 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121 Ok(())
122 } else {
123 let local_var_entity: Option<DeleteAllError> =
124 serde_json::from_str(&local_var_content).ok();
125 let local_var_error = ResponseContent {
126 status: local_var_status,
127 content: local_var_content,
128 entity: local_var_entity,
129 };
130 Err(Error::ResponseError(local_var_error))
131 }
132 }
133
134 async fn get<'a>(&self, id: &'a str) -> Result<models::FolderResponseModel, Error<GetError>> {
135 let local_var_configuration = &self.configuration;
136
137 let local_var_client = &local_var_configuration.client;
138
139 let local_var_uri_str = format!(
140 "{}/folders/{id}",
141 local_var_configuration.base_path,
142 id = crate::apis::urlencode(id)
143 );
144 let mut local_var_req_builder =
145 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
146
147 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
148
149 let local_var_resp = local_var_req_builder.send().await?;
150
151 let local_var_status = local_var_resp.status();
152 let local_var_content_type = local_var_resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let local_var_content_type = super::ContentType::from(local_var_content_type);
158 let local_var_content = local_var_resp.text().await?;
159
160 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161 match local_var_content_type {
162 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
163 ContentType::Text => {
164 return Err(Error::from(serde_json::Error::custom(
165 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
166 )));
167 }
168 ContentType::Unsupported(local_var_unknown_type) => {
169 return Err(Error::from(serde_json::Error::custom(format!(
170 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
171 ))));
172 }
173 }
174 } else {
175 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
176 let local_var_error = ResponseContent {
177 status: local_var_status,
178 content: local_var_content,
179 entity: local_var_entity,
180 };
181 Err(Error::ResponseError(local_var_error))
182 }
183 }
184
185 async fn get_all(
186 &self,
187 ) -> Result<models::FolderResponseModelListResponseModel, Error<GetAllError>> {
188 let local_var_configuration = &self.configuration;
189
190 let local_var_client = &local_var_configuration.client;
191
192 let local_var_uri_str = format!("{}/folders", local_var_configuration.base_path);
193 let mut local_var_req_builder =
194 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
195
196 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
197
198 let local_var_resp = local_var_req_builder.send().await?;
199
200 let local_var_status = local_var_resp.status();
201 let local_var_content_type = local_var_resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let local_var_content_type = super::ContentType::from(local_var_content_type);
207 let local_var_content = local_var_resp.text().await?;
208
209 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
210 match local_var_content_type {
211 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
212 ContentType::Text => {
213 return Err(Error::from(serde_json::Error::custom(
214 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModelListResponseModel`",
215 )));
216 }
217 ContentType::Unsupported(local_var_unknown_type) => {
218 return Err(Error::from(serde_json::Error::custom(format!(
219 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModelListResponseModel`"
220 ))));
221 }
222 }
223 } else {
224 let local_var_entity: Option<GetAllError> =
225 serde_json::from_str(&local_var_content).ok();
226 let local_var_error = ResponseContent {
227 status: local_var_status,
228 content: local_var_content,
229 entity: local_var_entity,
230 };
231 Err(Error::ResponseError(local_var_error))
232 }
233 }
234
235 async fn post<'a>(
236 &self,
237 folder_request_model: Option<models::FolderRequestModel>,
238 ) -> Result<models::FolderResponseModel, Error<PostError>> {
239 let local_var_configuration = &self.configuration;
240
241 let local_var_client = &local_var_configuration.client;
242
243 let local_var_uri_str = format!("{}/folders", local_var_configuration.base_path);
244 let mut local_var_req_builder =
245 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
246
247 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
248 local_var_req_builder = local_var_req_builder.json(&folder_request_model);
249
250 let local_var_resp = local_var_req_builder.send().await?;
251
252 let local_var_status = local_var_resp.status();
253 let local_var_content_type = local_var_resp
254 .headers()
255 .get("content-type")
256 .and_then(|v| v.to_str().ok())
257 .unwrap_or("application/octet-stream");
258 let local_var_content_type = super::ContentType::from(local_var_content_type);
259 let local_var_content = local_var_resp.text().await?;
260
261 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
262 match local_var_content_type {
263 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
264 ContentType::Text => {
265 return Err(Error::from(serde_json::Error::custom(
266 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
267 )));
268 }
269 ContentType::Unsupported(local_var_unknown_type) => {
270 return Err(Error::from(serde_json::Error::custom(format!(
271 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
272 ))));
273 }
274 }
275 } else {
276 let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
277 let local_var_error = ResponseContent {
278 status: local_var_status,
279 content: local_var_content,
280 entity: local_var_entity,
281 };
282 Err(Error::ResponseError(local_var_error))
283 }
284 }
285
286 async fn put<'a>(
287 &self,
288 id: &'a str,
289 folder_request_model: Option<models::FolderRequestModel>,
290 ) -> Result<models::FolderResponseModel, Error<PutError>> {
291 let local_var_configuration = &self.configuration;
292
293 let local_var_client = &local_var_configuration.client;
294
295 let local_var_uri_str = format!(
296 "{}/folders/{id}",
297 local_var_configuration.base_path,
298 id = crate::apis::urlencode(id)
299 );
300 let mut local_var_req_builder =
301 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
302
303 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
304 local_var_req_builder = local_var_req_builder.json(&folder_request_model);
305
306 let local_var_resp = local_var_req_builder.send().await?;
307
308 let local_var_status = local_var_resp.status();
309 let local_var_content_type = local_var_resp
310 .headers()
311 .get("content-type")
312 .and_then(|v| v.to_str().ok())
313 .unwrap_or("application/octet-stream");
314 let local_var_content_type = super::ContentType::from(local_var_content_type);
315 let local_var_content = local_var_resp.text().await?;
316
317 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
318 match local_var_content_type {
319 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
320 ContentType::Text => {
321 return Err(Error::from(serde_json::Error::custom(
322 "Received `text/plain` content type response that cannot be converted to `models::FolderResponseModel`",
323 )));
324 }
325 ContentType::Unsupported(local_var_unknown_type) => {
326 return Err(Error::from(serde_json::Error::custom(format!(
327 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::FolderResponseModel`"
328 ))));
329 }
330 }
331 } else {
332 let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
333 let local_var_error = ResponseContent {
334 status: local_var_status,
335 content: local_var_content,
336 entity: local_var_entity,
337 };
338 Err(Error::ResponseError(local_var_error))
339 }
340 }
341}
342
343#[derive(Debug, Clone, Serialize, Deserialize)]
345#[serde(untagged)]
346pub enum DeleteError {
347 UnknownValue(serde_json::Value),
348}
349#[derive(Debug, Clone, Serialize, Deserialize)]
351#[serde(untagged)]
352pub enum DeleteAllError {
353 UnknownValue(serde_json::Value),
354}
355#[derive(Debug, Clone, Serialize, Deserialize)]
357#[serde(untagged)]
358pub enum GetError {
359 UnknownValue(serde_json::Value),
360}
361#[derive(Debug, Clone, Serialize, Deserialize)]
363#[serde(untagged)]
364pub enum GetAllError {
365 UnknownValue(serde_json::Value),
366}
367#[derive(Debug, Clone, Serialize, Deserialize)]
369#[serde(untagged)]
370pub enum PostError {
371 UnknownValue(serde_json::Value),
372}
373#[derive(Debug, Clone, Serialize, Deserialize)]
375#[serde(untagged)]
376pub enum PutError {
377 UnknownValue(serde_json::Value),
378}