1use std::sync::Arc;
12
13use async_trait::async_trait;
14use reqwest;
15use serde::{de::Error as _, Deserialize, Serialize};
16
17use super::{configuration, Error};
18use crate::{
19 apis::{ContentType, ResponseContent},
20 models,
21};
22
23#[async_trait]
24pub trait FilesApi: Send + Sync {
25 async fn file_controller_create<'file>(
27 &self,
28 file: std::path::PathBuf,
29 ) -> Result<models::File, Error<FileControllerCreateError>>;
30
31 async fn file_controller_find_all(
33 &self,
34 ) -> Result<Vec<models::File>, Error<FileControllerFindAllError>>;
35
36 async fn file_controller_find_one<'id>(
38 &self,
39 id: &'id str,
40 ) -> Result<models::File, Error<FileControllerFindOneError>>;
41
42 async fn file_controller_remove<'id>(
44 &self,
45 id: &'id str,
46 ) -> Result<models::File, Error<FileControllerRemoveError>>;
47
48 async fn file_controller_update<'id>(
50 &self,
51 id: &'id str,
52 update_file_dto: models::UpdateFileDto,
53 ) -> Result<models::File, Error<FileControllerUpdateError>>;
54}
55
56pub struct FilesApiClient {
57 configuration: Arc<configuration::Configuration>,
58}
59
60impl FilesApiClient {
61 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
62 Self { configuration }
63 }
64}
65
66#[async_trait]
67impl FilesApi for FilesApiClient {
68 async fn file_controller_create<'file>(
69 &self,
70 file: std::path::PathBuf,
71 ) -> Result<models::File, Error<FileControllerCreateError>> {
72 let local_var_configuration = &self.configuration;
73 let local_var_client = &local_var_configuration.client;
74
75 let local_var_uri_str = format!("{}/file", local_var_configuration.base_path);
76 let mut local_var_req_builder =
77 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
78
79 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
80 local_var_req_builder = local_var_req_builder
81 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82 }
83 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
84 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85 };
86
87 let file_content = std::fs::read(&file)?;
88 let file_part = reqwest::multipart::Part::bytes(file_content).file_name(
89 file.file_name()
90 .unwrap_or_default()
91 .to_string_lossy()
92 .to_string(),
93 );
94 let local_var_form = reqwest::multipart::Form::new().part("file", file_part);
95 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
96
97 let local_var_req = local_var_req_builder.build()?;
98 let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100 let local_var_status = local_var_resp.status();
101 let local_var_content_type = local_var_resp
102 .headers()
103 .get("content-type")
104 .and_then(|v| v.to_str().ok())
105 .unwrap_or("application/octet-stream");
106 let local_var_content_type = ContentType::from(local_var_content_type);
107 let local_var_content = local_var_resp.text().await?;
108
109 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
110 match local_var_content_type {
111 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
112 ContentType::Text => Err(Error::from(serde_json::Error::custom(
113 "Received `text/plain` content type response that cannot be converted to \
114 `models::File`",
115 ))),
116 ContentType::Unsupported(local_var_unknown_type) => {
117 Err(Error::from(serde_json::Error::custom(format!(
118 "Received `{local_var_unknown_type}` content type response that cannot be \
119 converted to `models::File`"
120 ))))
121 }
122 }
123 } else {
124 let local_var_entity: Option<FileControllerCreateError> =
125 serde_json::from_str(&local_var_content).ok();
126 let local_var_error = ResponseContent {
127 status: local_var_status,
128 content: local_var_content,
129 entity: local_var_entity,
130 };
131 Err(Error::ResponseError(local_var_error))
132 }
133 }
134
135 async fn file_controller_find_all(
136 &self,
137 ) -> Result<Vec<models::File>, Error<FileControllerFindAllError>> {
138 let local_var_configuration = &self.configuration;
139 let local_var_client = &local_var_configuration.client;
140
141 let local_var_uri_str = format!("{}/file", local_var_configuration.base_path);
142 let mut local_var_req_builder =
143 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder = local_var_req_builder
147 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148 }
149 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
150 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
151 };
152
153 let local_var_req = local_var_req_builder.build()?;
154 let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156 let local_var_status = local_var_resp.status();
157 let local_var_content_type = local_var_resp
158 .headers()
159 .get("content-type")
160 .and_then(|v| v.to_str().ok())
161 .unwrap_or("application/octet-stream");
162 let local_var_content_type = ContentType::from(local_var_content_type);
163 let local_var_content = local_var_resp.text().await?;
164
165 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166 match local_var_content_type {
167 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
168 ContentType::Text => Err(Error::from(serde_json::Error::custom(
169 "Received `text/plain` content type response that cannot be converted to \
170 `Vec<models::File>`",
171 ))),
172 ContentType::Unsupported(local_var_unknown_type) => {
173 Err(Error::from(serde_json::Error::custom(format!(
174 "Received `{local_var_unknown_type}` content type response that cannot be \
175 converted to `Vec<models::File>`"
176 ))))
177 }
178 }
179 } else {
180 let local_var_entity: Option<FileControllerFindAllError> =
181 serde_json::from_str(&local_var_content).ok();
182 let local_var_error = ResponseContent {
183 status: local_var_status,
184 content: local_var_content,
185 entity: local_var_entity,
186 };
187 Err(Error::ResponseError(local_var_error))
188 }
189 }
190
191 async fn file_controller_find_one<'id>(
192 &self,
193 id: &'id str,
194 ) -> Result<models::File, Error<FileControllerFindOneError>> {
195 let local_var_configuration = &self.configuration;
196 let local_var_client = &local_var_configuration.client;
197
198 let local_var_uri_str = format!(
199 "{}/file/{id}",
200 local_var_configuration.base_path,
201 id = crate::apis::urlencode(id)
202 );
203 let mut local_var_req_builder =
204 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
205
206 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
207 local_var_req_builder = local_var_req_builder
208 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
209 }
210 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
211 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
212 };
213
214 let local_var_req = local_var_req_builder.build()?;
215 let local_var_resp = local_var_client.execute(local_var_req).await?;
216
217 let local_var_status = local_var_resp.status();
218 let local_var_content_type = local_var_resp
219 .headers()
220 .get("content-type")
221 .and_then(|v| v.to_str().ok())
222 .unwrap_or("application/octet-stream");
223 let local_var_content_type = ContentType::from(local_var_content_type);
224 let local_var_content = local_var_resp.text().await?;
225
226 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
227 match local_var_content_type {
228 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
229 ContentType::Text => Err(Error::from(serde_json::Error::custom(
230 "Received `text/plain` content type response that cannot be converted to \
231 `models::File`",
232 ))),
233 ContentType::Unsupported(local_var_unknown_type) => {
234 Err(Error::from(serde_json::Error::custom(format!(
235 "Received `{local_var_unknown_type}` content type response that cannot be \
236 converted to `models::File`"
237 ))))
238 }
239 }
240 } else {
241 let local_var_entity: Option<FileControllerFindOneError> =
242 serde_json::from_str(&local_var_content).ok();
243 let local_var_error = ResponseContent {
244 status: local_var_status,
245 content: local_var_content,
246 entity: local_var_entity,
247 };
248 Err(Error::ResponseError(local_var_error))
249 }
250 }
251
252 async fn file_controller_remove<'id>(
253 &self,
254 id: &'id str,
255 ) -> Result<models::File, Error<FileControllerRemoveError>> {
256 let local_var_configuration = &self.configuration;
257 let local_var_client = &local_var_configuration.client;
258
259 let local_var_uri_str = format!(
260 "{}/file/{id}",
261 local_var_configuration.base_path,
262 id = crate::apis::urlencode(id)
263 );
264 let mut local_var_req_builder =
265 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
266
267 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
268 local_var_req_builder = local_var_req_builder
269 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
270 }
271 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
272 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
273 };
274
275 let local_var_req = local_var_req_builder.build()?;
276 let local_var_resp = local_var_client.execute(local_var_req).await?;
277
278 let local_var_status = local_var_resp.status();
279 let local_var_content_type = local_var_resp
280 .headers()
281 .get("content-type")
282 .and_then(|v| v.to_str().ok())
283 .unwrap_or("application/octet-stream");
284 let local_var_content_type = ContentType::from(local_var_content_type);
285 let local_var_content = local_var_resp.text().await?;
286
287 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
288 match local_var_content_type {
289 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
290 ContentType::Text => Err(Error::from(serde_json::Error::custom(
291 "Received `text/plain` content type response that cannot be converted to \
292 `models::File`",
293 ))),
294 ContentType::Unsupported(local_var_unknown_type) => {
295 Err(Error::from(serde_json::Error::custom(format!(
296 "Received `{local_var_unknown_type}` content type response that cannot be \
297 converted to `models::File`"
298 ))))
299 }
300 }
301 } else {
302 let local_var_entity: Option<FileControllerRemoveError> =
303 serde_json::from_str(&local_var_content).ok();
304 let local_var_error = ResponseContent {
305 status: local_var_status,
306 content: local_var_content,
307 entity: local_var_entity,
308 };
309 Err(Error::ResponseError(local_var_error))
310 }
311 }
312
313 async fn file_controller_update<'id>(
314 &self,
315 id: &'id str,
316 update_file_dto: models::UpdateFileDto,
317 ) -> Result<models::File, Error<FileControllerUpdateError>> {
318 let local_var_configuration = &self.configuration;
319 let local_var_client = &local_var_configuration.client;
320
321 let local_var_uri_str = format!(
322 "{}/file/{id}",
323 local_var_configuration.base_path,
324 id = crate::apis::urlencode(id)
325 );
326 let mut local_var_req_builder =
327 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
328
329 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
330 local_var_req_builder = local_var_req_builder
331 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
332 }
333 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
334 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
335 };
336 local_var_req_builder = local_var_req_builder.json(&update_file_dto);
337
338 let local_var_req = local_var_req_builder.build()?;
339 let local_var_resp = local_var_client.execute(local_var_req).await?;
340
341 let local_var_status = local_var_resp.status();
342 let local_var_content_type = local_var_resp
343 .headers()
344 .get("content-type")
345 .and_then(|v| v.to_str().ok())
346 .unwrap_or("application/octet-stream");
347 let local_var_content_type = ContentType::from(local_var_content_type);
348 let local_var_content = local_var_resp.text().await?;
349
350 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
351 match local_var_content_type {
352 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
353 ContentType::Text => Err(Error::from(serde_json::Error::custom(
354 "Received `text/plain` content type response that cannot be converted to \
355 `models::File`",
356 ))),
357 ContentType::Unsupported(local_var_unknown_type) => {
358 Err(Error::from(serde_json::Error::custom(format!(
359 "Received `{local_var_unknown_type}` content type response that cannot be \
360 converted to `models::File`"
361 ))))
362 }
363 }
364 } else {
365 let local_var_entity: Option<FileControllerUpdateError> =
366 serde_json::from_str(&local_var_content).ok();
367 let local_var_error = ResponseContent {
368 status: local_var_status,
369 content: local_var_content,
370 entity: local_var_entity,
371 };
372 Err(Error::ResponseError(local_var_error))
373 }
374 }
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum FileControllerCreateError {
381 Status400(),
382 UnknownValue(serde_json::Value),
383}
384
385#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum FileControllerFindAllError {
389 UnknownValue(serde_json::Value),
390}
391
392#[derive(Debug, Clone, Serialize, Deserialize)]
394#[serde(untagged)]
395pub enum FileControllerFindOneError {
396 UnknownValue(serde_json::Value),
397}
398
399#[derive(Debug, Clone, Serialize, Deserialize)]
401#[serde(untagged)]
402pub enum FileControllerRemoveError {
403 UnknownValue(serde_json::Value),
404}
405
406#[derive(Debug, Clone, Serialize, Deserialize)]
408#[serde(untagged)]
409pub enum FileControllerUpdateError {
410 UnknownValue(serde_json::Value),
411}