1use super::{configuration, Error};
12use crate::gen::apis::ResponseContent;
13use crate::gen::models;
14
15#[derive(Clone, Debug)]
17pub struct CreateComponentParams {
18 pub component: models::Component,
19}
20
21#[derive(Clone, Debug)]
23pub struct DeleteComponentParams {
24 pub id: String,
26 pub move_issues_to: Option<String>,
28}
29
30#[derive(Clone, Debug)]
32pub struct GetComponentParams {
33 pub id: String,
35}
36
37#[derive(Clone, Debug)]
39pub struct GetComponentRelatedIssuesParams {
40 pub id: String,
42}
43
44#[derive(Clone, Debug)]
46pub struct GetProjectComponentsParams {
47 pub project_id_or_key: String,
49}
50
51#[derive(Clone, Debug)]
53pub struct GetProjectComponentsPaginatedParams {
54 pub project_id_or_key: String,
56 pub start_at: Option<i64>,
58 pub max_results: Option<i32>,
60 pub order_by: Option<String>,
62 pub query: Option<String>,
64}
65
66#[derive(Clone, Debug)]
68pub struct UpdateComponentParams {
69 pub id: String,
71 pub component: models::Component,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum CreateComponentError {
78 Status400(),
79 Status401(),
80 Status403(),
81 Status404(),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum DeleteComponentError {
89 Status401(),
90 Status403(),
91 Status404(),
92 UnknownValue(serde_json::Value),
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum GetComponentError {
99 Status401(),
100 Status404(),
101 UnknownValue(serde_json::Value),
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum GetComponentRelatedIssuesError {
108 Status401(),
109 Status404(),
110 UnknownValue(serde_json::Value),
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum GetProjectComponentsError {
117 Status401(),
118 Status404(),
119 UnknownValue(serde_json::Value),
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum GetProjectComponentsPaginatedError {
126 Status401(),
127 Status404(),
128 UnknownValue(serde_json::Value),
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum UpdateComponentError {
135 Status400(),
136 Status401(),
137 Status403(),
138 Status404(),
139 UnknownValue(serde_json::Value),
140}
141
142pub async fn create_component(
144 configuration: &configuration::Configuration,
145 params: CreateComponentParams,
146) -> Result<models::Component, Error<CreateComponentError>> {
147 let component = params.component;
149
150 let local_var_client = &configuration.client;
151
152 let local_var_uri_str = format!("{}/rest/api/3/component", configuration.base_path);
153 let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
154
155 if let Some(ref local_var_user_agent) = configuration.user_agent {
156 local_var_req_builder =
157 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158 }
159 if let Some(ref local_var_token) = configuration.oauth_access_token {
160 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161 };
162 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
163 local_var_req_builder = local_var_req_builder.basic_auth(
164 local_var_auth_conf.0.to_owned(),
165 local_var_auth_conf.1.to_owned(),
166 );
167 };
168 local_var_req_builder = local_var_req_builder.json(&component);
169
170 let local_var_req = local_var_req_builder.build()?;
171 let local_var_resp = local_var_client.execute(local_var_req).await?;
172
173 let local_var_status = local_var_resp.status();
174 let local_var_content = local_var_resp.text().await?;
175
176 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
177 serde_json::from_str(&local_var_content).map_err(Error::from)
178 } else {
179 let local_var_entity: Option<CreateComponentError> =
180 serde_json::from_str(&local_var_content).ok();
181 let local_var_error = ResponseContent {
182 status: local_var_status,
183 content: local_var_content,
184 entity: local_var_entity,
185 };
186 Err(Error::ResponseError(local_var_error))
187 }
188}
189
190pub async fn delete_component(
192 configuration: &configuration::Configuration,
193 params: DeleteComponentParams,
194) -> Result<(), Error<DeleteComponentError>> {
195 let id = params.id;
197 let move_issues_to = params.move_issues_to;
198
199 let local_var_client = &configuration.client;
200
201 let local_var_uri_str = format!(
202 "{}/rest/api/3/component/{id}",
203 configuration.base_path,
204 id = crate::gen::apis::urlencode(id)
205 );
206 let mut local_var_req_builder = local_var_client.delete(local_var_uri_str.as_str());
207
208 if let Some(ref local_var_str) = move_issues_to {
209 local_var_req_builder =
210 local_var_req_builder.query(&[("moveIssuesTo", &local_var_str.to_string())]);
211 }
212 if let Some(ref local_var_user_agent) = configuration.user_agent {
213 local_var_req_builder =
214 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215 }
216 if let Some(ref local_var_token) = configuration.oauth_access_token {
217 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
218 };
219 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
220 local_var_req_builder = local_var_req_builder.basic_auth(
221 local_var_auth_conf.0.to_owned(),
222 local_var_auth_conf.1.to_owned(),
223 );
224 };
225
226 let local_var_req = local_var_req_builder.build()?;
227 let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229 let local_var_status = local_var_resp.status();
230 let local_var_content = local_var_resp.text().await?;
231
232 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233 Ok(())
234 } else {
235 let local_var_entity: Option<DeleteComponentError> =
236 serde_json::from_str(&local_var_content).ok();
237 let local_var_error = ResponseContent {
238 status: local_var_status,
239 content: local_var_content,
240 entity: local_var_entity,
241 };
242 Err(Error::ResponseError(local_var_error))
243 }
244}
245
246pub async fn get_component(
248 configuration: &configuration::Configuration,
249 params: GetComponentParams,
250) -> Result<models::Component, Error<GetComponentError>> {
251 let id = params.id;
253
254 let local_var_client = &configuration.client;
255
256 let local_var_uri_str = format!(
257 "{}/rest/api/3/component/{id}",
258 configuration.base_path,
259 id = crate::gen::apis::urlencode(id)
260 );
261 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
262
263 if let Some(ref local_var_user_agent) = configuration.user_agent {
264 local_var_req_builder =
265 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
266 }
267 if let Some(ref local_var_token) = configuration.oauth_access_token {
268 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
269 };
270 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
271 local_var_req_builder = local_var_req_builder.basic_auth(
272 local_var_auth_conf.0.to_owned(),
273 local_var_auth_conf.1.to_owned(),
274 );
275 };
276
277 let local_var_req = local_var_req_builder.build()?;
278 let local_var_resp = local_var_client.execute(local_var_req).await?;
279
280 let local_var_status = local_var_resp.status();
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 serde_json::from_str(&local_var_content).map_err(Error::from)
285 } else {
286 let local_var_entity: Option<GetComponentError> =
287 serde_json::from_str(&local_var_content).ok();
288 let local_var_error = ResponseContent {
289 status: local_var_status,
290 content: local_var_content,
291 entity: local_var_entity,
292 };
293 Err(Error::ResponseError(local_var_error))
294 }
295}
296
297pub async fn get_component_related_issues(
299 configuration: &configuration::Configuration,
300 params: GetComponentRelatedIssuesParams,
301) -> Result<models::ComponentIssuesCount, Error<GetComponentRelatedIssuesError>> {
302 let id = params.id;
304
305 let local_var_client = &configuration.client;
306
307 let local_var_uri_str = format!(
308 "{}/rest/api/3/component/{id}/relatedIssueCounts",
309 configuration.base_path,
310 id = crate::gen::apis::urlencode(id)
311 );
312 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
313
314 if let Some(ref local_var_user_agent) = configuration.user_agent {
315 local_var_req_builder =
316 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
317 }
318 if let Some(ref local_var_token) = configuration.oauth_access_token {
319 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
320 };
321 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
322 local_var_req_builder = local_var_req_builder.basic_auth(
323 local_var_auth_conf.0.to_owned(),
324 local_var_auth_conf.1.to_owned(),
325 );
326 };
327
328 let local_var_req = local_var_req_builder.build()?;
329 let local_var_resp = local_var_client.execute(local_var_req).await?;
330
331 let local_var_status = local_var_resp.status();
332 let local_var_content = local_var_resp.text().await?;
333
334 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
335 serde_json::from_str(&local_var_content).map_err(Error::from)
336 } else {
337 let local_var_entity: Option<GetComponentRelatedIssuesError> =
338 serde_json::from_str(&local_var_content).ok();
339 let local_var_error = ResponseContent {
340 status: local_var_status,
341 content: local_var_content,
342 entity: local_var_entity,
343 };
344 Err(Error::ResponseError(local_var_error))
345 }
346}
347
348pub async fn get_project_components(
350 configuration: &configuration::Configuration,
351 params: GetProjectComponentsParams,
352) -> Result<Vec<models::Component>, Error<GetProjectComponentsError>> {
353 let project_id_or_key = params.project_id_or_key;
355
356 let local_var_client = &configuration.client;
357
358 let local_var_uri_str = format!(
359 "{}/rest/api/3/project/{projectIdOrKey}/components",
360 configuration.base_path,
361 projectIdOrKey = crate::gen::apis::urlencode(project_id_or_key)
362 );
363 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
364
365 if let Some(ref local_var_user_agent) = configuration.user_agent {
366 local_var_req_builder =
367 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
368 }
369 if let Some(ref local_var_token) = configuration.oauth_access_token {
370 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
371 };
372 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
373 local_var_req_builder = local_var_req_builder.basic_auth(
374 local_var_auth_conf.0.to_owned(),
375 local_var_auth_conf.1.to_owned(),
376 );
377 };
378
379 let local_var_req = local_var_req_builder.build()?;
380 let local_var_resp = local_var_client.execute(local_var_req).await?;
381
382 let local_var_status = local_var_resp.status();
383 let local_var_content = local_var_resp.text().await?;
384
385 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
386 serde_json::from_str(&local_var_content).map_err(Error::from)
387 } else {
388 let local_var_entity: Option<GetProjectComponentsError> =
389 serde_json::from_str(&local_var_content).ok();
390 let local_var_error = ResponseContent {
391 status: local_var_status,
392 content: local_var_content,
393 entity: local_var_entity,
394 };
395 Err(Error::ResponseError(local_var_error))
396 }
397}
398
399pub async fn get_project_components_paginated(
401 configuration: &configuration::Configuration,
402 params: GetProjectComponentsPaginatedParams,
403) -> Result<models::PageBeanComponentWithIssueCount, Error<GetProjectComponentsPaginatedError>> {
404 let project_id_or_key = params.project_id_or_key;
406 let start_at = params.start_at;
407 let max_results = params.max_results;
408 let order_by = params.order_by;
409 let query = params.query;
410
411 let local_var_client = &configuration.client;
412
413 let local_var_uri_str = format!(
414 "{}/rest/api/3/project/{projectIdOrKey}/component",
415 configuration.base_path,
416 projectIdOrKey = crate::gen::apis::urlencode(project_id_or_key)
417 );
418 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
419
420 if let Some(ref local_var_str) = start_at {
421 local_var_req_builder =
422 local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
423 }
424 if let Some(ref local_var_str) = max_results {
425 local_var_req_builder =
426 local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
427 }
428 if let Some(ref local_var_str) = order_by {
429 local_var_req_builder =
430 local_var_req_builder.query(&[("orderBy", &local_var_str.to_string())]);
431 }
432 if let Some(ref local_var_str) = query {
433 local_var_req_builder =
434 local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
435 }
436 if let Some(ref local_var_user_agent) = configuration.user_agent {
437 local_var_req_builder =
438 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
439 }
440 if let Some(ref local_var_token) = configuration.oauth_access_token {
441 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
442 };
443 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
444 local_var_req_builder = local_var_req_builder.basic_auth(
445 local_var_auth_conf.0.to_owned(),
446 local_var_auth_conf.1.to_owned(),
447 );
448 };
449
450 let local_var_req = local_var_req_builder.build()?;
451 let local_var_resp = local_var_client.execute(local_var_req).await?;
452
453 let local_var_status = local_var_resp.status();
454 let local_var_content = local_var_resp.text().await?;
455
456 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
457 serde_json::from_str(&local_var_content).map_err(Error::from)
458 } else {
459 let local_var_entity: Option<GetProjectComponentsPaginatedError> =
460 serde_json::from_str(&local_var_content).ok();
461 let local_var_error = ResponseContent {
462 status: local_var_status,
463 content: local_var_content,
464 entity: local_var_entity,
465 };
466 Err(Error::ResponseError(local_var_error))
467 }
468}
469
470pub async fn update_component(
472 configuration: &configuration::Configuration,
473 params: UpdateComponentParams,
474) -> Result<models::Component, Error<UpdateComponentError>> {
475 let id = params.id;
477 let component = params.component;
478
479 let local_var_client = &configuration.client;
480
481 let local_var_uri_str = format!(
482 "{}/rest/api/3/component/{id}",
483 configuration.base_path,
484 id = crate::gen::apis::urlencode(id)
485 );
486 let mut local_var_req_builder = local_var_client.put(local_var_uri_str.as_str());
487
488 if let Some(ref local_var_user_agent) = configuration.user_agent {
489 local_var_req_builder =
490 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
491 }
492 if let Some(ref local_var_token) = configuration.oauth_access_token {
493 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
494 };
495 if let Some(ref local_var_auth_conf) = configuration.basic_auth {
496 local_var_req_builder = local_var_req_builder.basic_auth(
497 local_var_auth_conf.0.to_owned(),
498 local_var_auth_conf.1.to_owned(),
499 );
500 };
501 local_var_req_builder = local_var_req_builder.json(&component);
502
503 let local_var_req = local_var_req_builder.build()?;
504 let local_var_resp = local_var_client.execute(local_var_req).await?;
505
506 let local_var_status = local_var_resp.status();
507 let local_var_content = local_var_resp.text().await?;
508
509 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
510 serde_json::from_str(&local_var_content).map_err(Error::from)
511 } else {
512 let local_var_entity: Option<UpdateComponentError> =
513 serde_json::from_str(&local_var_content).ok();
514 let local_var_error = ResponseContent {
515 status: local_var_status,
516 content: local_var_content,
517 entity: local_var_entity,
518 };
519 Err(Error::ResponseError(local_var_error))
520 }
521}