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 ProjectsApi: Send + Sync {
29 async fn bulk_delete<'a>(
31 &self,
32 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
33 ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>>;
34
35 async fn create<'a>(
37 &self,
38 organization_id: uuid::Uuid,
39 project_create_request_model: Option<models::ProjectCreateRequestModel>,
40 ) -> Result<models::ProjectResponseModel, Error<CreateError>>;
41
42 async fn get<'a>(
44 &self,
45 id: uuid::Uuid,
46 ) -> Result<models::ProjectResponseModel, Error<GetError>>;
47
48 async fn list_by_organization<'a>(
50 &self,
51 organization_id: uuid::Uuid,
52 ) -> Result<models::ProjectResponseModelListResponseModel, Error<ListByOrganizationError>>;
53
54 async fn update<'a>(
56 &self,
57 id: uuid::Uuid,
58 project_update_request_model: Option<models::ProjectUpdateRequestModel>,
59 ) -> Result<models::ProjectResponseModel, Error<UpdateError>>;
60}
61
62pub struct ProjectsApiClient {
63 configuration: Arc<configuration::Configuration>,
64}
65
66impl ProjectsApiClient {
67 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
68 Self { configuration }
69 }
70}
71
72#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
73#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
74impl ProjectsApi for ProjectsApiClient {
75 async fn bulk_delete<'a>(
76 &self,
77 uuid_colon_colon_uuid: Option<Vec<uuid::Uuid>>,
78 ) -> Result<models::BulkDeleteResponseModelListResponseModel, Error<BulkDeleteError>> {
79 let local_var_configuration = &self.configuration;
80
81 let local_var_client = &local_var_configuration.client;
82
83 let local_var_uri_str = format!("{}/projects/delete", local_var_configuration.base_path);
84 let mut local_var_req_builder =
85 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
86
87 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
88 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
89 };
90 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
91 local_var_req_builder = local_var_req_builder.json(&uuid_colon_colon_uuid);
92
93 let local_var_req = local_var_req_builder.build()?;
94 let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96 let local_var_status = local_var_resp.status();
97 let local_var_content_type = local_var_resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let local_var_content_type = super::ContentType::from(local_var_content_type);
103 let local_var_content = local_var_resp.text().await?;
104
105 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
106 match local_var_content_type {
107 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
108 ContentType::Text => {
109 return Err(Error::from(serde_json::Error::custom(
110 "Received `text/plain` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`",
111 )));
112 }
113 ContentType::Unsupported(local_var_unknown_type) => {
114 return Err(Error::from(serde_json::Error::custom(format!(
115 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::BulkDeleteResponseModelListResponseModel`"
116 ))));
117 }
118 }
119 } else {
120 let local_var_entity: Option<BulkDeleteError> =
121 serde_json::from_str(&local_var_content).ok();
122 let local_var_error = ResponseContent {
123 status: local_var_status,
124 content: local_var_content,
125 entity: local_var_entity,
126 };
127 Err(Error::ResponseError(local_var_error))
128 }
129 }
130
131 async fn create<'a>(
132 &self,
133 organization_id: uuid::Uuid,
134 project_create_request_model: Option<models::ProjectCreateRequestModel>,
135 ) -> Result<models::ProjectResponseModel, Error<CreateError>> {
136 let local_var_configuration = &self.configuration;
137
138 let local_var_client = &local_var_configuration.client;
139
140 let local_var_uri_str = format!(
141 "{}/organizations/{organizationId}/projects",
142 local_var_configuration.base_path,
143 organizationId = organization_id
144 );
145 let mut local_var_req_builder =
146 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
147
148 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
149 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150 };
151 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
152 local_var_req_builder = local_var_req_builder.json(&project_create_request_model);
153
154 let local_var_req = local_var_req_builder.build()?;
155 let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157 let local_var_status = local_var_resp.status();
158 let local_var_content_type = local_var_resp
159 .headers()
160 .get("content-type")
161 .and_then(|v| v.to_str().ok())
162 .unwrap_or("application/octet-stream");
163 let local_var_content_type = super::ContentType::from(local_var_content_type);
164 let local_var_content = local_var_resp.text().await?;
165
166 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167 match local_var_content_type {
168 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
169 ContentType::Text => {
170 return Err(Error::from(serde_json::Error::custom(
171 "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
172 )));
173 }
174 ContentType::Unsupported(local_var_unknown_type) => {
175 return Err(Error::from(serde_json::Error::custom(format!(
176 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
177 ))));
178 }
179 }
180 } else {
181 let local_var_entity: Option<CreateError> =
182 serde_json::from_str(&local_var_content).ok();
183 let local_var_error = ResponseContent {
184 status: local_var_status,
185 content: local_var_content,
186 entity: local_var_entity,
187 };
188 Err(Error::ResponseError(local_var_error))
189 }
190 }
191
192 async fn get<'a>(
193 &self,
194 id: uuid::Uuid,
195 ) -> Result<models::ProjectResponseModel, Error<GetError>> {
196 let local_var_configuration = &self.configuration;
197
198 let local_var_client = &local_var_configuration.client;
199
200 let local_var_uri_str = format!(
201 "{}/projects/{id}",
202 local_var_configuration.base_path,
203 id = id
204 );
205 let mut local_var_req_builder =
206 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
207
208 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
209 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
210 };
211 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
212
213 let local_var_req = local_var_req_builder.build()?;
214 let local_var_resp = local_var_client.execute(local_var_req).await?;
215
216 let local_var_status = local_var_resp.status();
217 let local_var_content_type = local_var_resp
218 .headers()
219 .get("content-type")
220 .and_then(|v| v.to_str().ok())
221 .unwrap_or("application/octet-stream");
222 let local_var_content_type = super::ContentType::from(local_var_content_type);
223 let local_var_content = local_var_resp.text().await?;
224
225 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
226 match local_var_content_type {
227 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
228 ContentType::Text => {
229 return Err(Error::from(serde_json::Error::custom(
230 "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
231 )));
232 }
233 ContentType::Unsupported(local_var_unknown_type) => {
234 return Err(Error::from(serde_json::Error::custom(format!(
235 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
236 ))));
237 }
238 }
239 } else {
240 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
241 let local_var_error = ResponseContent {
242 status: local_var_status,
243 content: local_var_content,
244 entity: local_var_entity,
245 };
246 Err(Error::ResponseError(local_var_error))
247 }
248 }
249
250 async fn list_by_organization<'a>(
251 &self,
252 organization_id: uuid::Uuid,
253 ) -> Result<models::ProjectResponseModelListResponseModel, Error<ListByOrganizationError>> {
254 let local_var_configuration = &self.configuration;
255
256 let local_var_client = &local_var_configuration.client;
257
258 let local_var_uri_str = format!(
259 "{}/organizations/{organizationId}/projects",
260 local_var_configuration.base_path,
261 organizationId = organization_id
262 );
263 let mut local_var_req_builder =
264 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
265
266 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
267 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
268 };
269 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
270
271 let local_var_req = local_var_req_builder.build()?;
272 let local_var_resp = local_var_client.execute(local_var_req).await?;
273
274 let local_var_status = local_var_resp.status();
275 let local_var_content_type = local_var_resp
276 .headers()
277 .get("content-type")
278 .and_then(|v| v.to_str().ok())
279 .unwrap_or("application/octet-stream");
280 let local_var_content_type = super::ContentType::from(local_var_content_type);
281 let local_var_content = local_var_resp.text().await?;
282
283 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
284 match local_var_content_type {
285 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
286 ContentType::Text => {
287 return Err(Error::from(serde_json::Error::custom(
288 "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`",
289 )));
290 }
291 ContentType::Unsupported(local_var_unknown_type) => {
292 return Err(Error::from(serde_json::Error::custom(format!(
293 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModelListResponseModel`"
294 ))));
295 }
296 }
297 } else {
298 let local_var_entity: Option<ListByOrganizationError> =
299 serde_json::from_str(&local_var_content).ok();
300 let local_var_error = ResponseContent {
301 status: local_var_status,
302 content: local_var_content,
303 entity: local_var_entity,
304 };
305 Err(Error::ResponseError(local_var_error))
306 }
307 }
308
309 async fn update<'a>(
310 &self,
311 id: uuid::Uuid,
312 project_update_request_model: Option<models::ProjectUpdateRequestModel>,
313 ) -> Result<models::ProjectResponseModel, Error<UpdateError>> {
314 let local_var_configuration = &self.configuration;
315
316 let local_var_client = &local_var_configuration.client;
317
318 let local_var_uri_str = format!(
319 "{}/projects/{id}",
320 local_var_configuration.base_path,
321 id = id
322 );
323 let mut local_var_req_builder =
324 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
325
326 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
327 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
328 };
329 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
330 local_var_req_builder = local_var_req_builder.json(&project_update_request_model);
331
332 let local_var_req = local_var_req_builder.build()?;
333 let local_var_resp = local_var_client.execute(local_var_req).await?;
334
335 let local_var_status = local_var_resp.status();
336 let local_var_content_type = local_var_resp
337 .headers()
338 .get("content-type")
339 .and_then(|v| v.to_str().ok())
340 .unwrap_or("application/octet-stream");
341 let local_var_content_type = super::ContentType::from(local_var_content_type);
342 let local_var_content = local_var_resp.text().await?;
343
344 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
345 match local_var_content_type {
346 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
347 ContentType::Text => {
348 return Err(Error::from(serde_json::Error::custom(
349 "Received `text/plain` content type response that cannot be converted to `models::ProjectResponseModel`",
350 )));
351 }
352 ContentType::Unsupported(local_var_unknown_type) => {
353 return Err(Error::from(serde_json::Error::custom(format!(
354 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectResponseModel`"
355 ))));
356 }
357 }
358 } else {
359 let local_var_entity: Option<UpdateError> =
360 serde_json::from_str(&local_var_content).ok();
361 let local_var_error = ResponseContent {
362 status: local_var_status,
363 content: local_var_content,
364 entity: local_var_entity,
365 };
366 Err(Error::ResponseError(local_var_error))
367 }
368 }
369}
370
371#[derive(Debug, Clone, Serialize, Deserialize)]
373#[serde(untagged)]
374pub enum BulkDeleteError {
375 UnknownValue(serde_json::Value),
376}
377#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum CreateError {
381 UnknownValue(serde_json::Value),
382}
383#[derive(Debug, Clone, Serialize, Deserialize)]
385#[serde(untagged)]
386pub enum GetError {
387 UnknownValue(serde_json::Value),
388}
389#[derive(Debug, Clone, Serialize, Deserialize)]
391#[serde(untagged)]
392pub enum ListByOrganizationError {
393 UnknownValue(serde_json::Value),
394}
395#[derive(Debug, Clone, Serialize, Deserialize)]
397#[serde(untagged)]
398pub enum UpdateError {
399 UnknownValue(serde_json::Value),
400}