jira/gen/apis/
project_components_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::gen::apis::ResponseContent;
13use crate::gen::models;
14
15/// struct for passing parameters to the method `create_component`
16#[derive(Clone, Debug)]
17pub struct CreateComponentParams {
18    pub component: models::Component,
19}
20
21/// struct for passing parameters to the method `delete_component`
22#[derive(Clone, Debug)]
23pub struct DeleteComponentParams {
24    /// The ID of the component.
25    pub id: String,
26    /// The ID of the component to replace the deleted component. If this value is null no replacement is made.
27    pub move_issues_to: Option<String>,
28}
29
30/// struct for passing parameters to the method `get_component`
31#[derive(Clone, Debug)]
32pub struct GetComponentParams {
33    /// The ID of the component.
34    pub id: String,
35}
36
37/// struct for passing parameters to the method `get_component_related_issues`
38#[derive(Clone, Debug)]
39pub struct GetComponentRelatedIssuesParams {
40    /// The ID of the component.
41    pub id: String,
42}
43
44/// struct for passing parameters to the method `get_project_components`
45#[derive(Clone, Debug)]
46pub struct GetProjectComponentsParams {
47    /// The project ID or project key (case sensitive).
48    pub project_id_or_key: String,
49}
50
51/// struct for passing parameters to the method `get_project_components_paginated`
52#[derive(Clone, Debug)]
53pub struct GetProjectComponentsPaginatedParams {
54    /// The project ID or project key (case sensitive).
55    pub project_id_or_key: String,
56    /// The index of the first item to return in a page of results (page offset).
57    pub start_at: Option<i64>,
58    /// The maximum number of items to return per page.
59    pub max_results: Option<i32>,
60    /// [Order](#ordering) the results by a field:   *  `description` Sorts by the component description.  *  `issueCount` Sorts by the count of issues associated with the component.  *  `lead` Sorts by the user key of the component's project lead.  *  `name` Sorts by component name.
61    pub order_by: Option<String>,
62    /// Filter the results using a literal string. Components with a matching `name` or `description` are returned (case insensitive).
63    pub query: Option<String>,
64}
65
66/// struct for passing parameters to the method `update_component`
67#[derive(Clone, Debug)]
68pub struct UpdateComponentParams {
69    /// The ID of the component.
70    pub id: String,
71    pub component: models::Component,
72}
73
74/// struct for typed errors of method `create_component`
75#[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/// struct for typed errors of method `delete_component`
86#[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/// struct for typed errors of method `get_component`
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum GetComponentError {
99    Status401(),
100    Status404(),
101    UnknownValue(serde_json::Value),
102}
103
104/// struct for typed errors of method `get_component_related_issues`
105#[derive(Debug, Clone, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum GetComponentRelatedIssuesError {
108    Status401(),
109    Status404(),
110    UnknownValue(serde_json::Value),
111}
112
113/// struct for typed errors of method `get_project_components`
114#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum GetProjectComponentsError {
117    Status401(),
118    Status404(),
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method `get_project_components_paginated`
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum GetProjectComponentsPaginatedError {
126    Status401(),
127    Status404(),
128    UnknownValue(serde_json::Value),
129}
130
131/// struct for typed errors of method `update_component`
132#[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
142/// Creates a component. Use components to provide containers for issues within a project.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project in which the component is created or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
143pub async fn create_component(
144    configuration: &configuration::Configuration,
145    params: CreateComponentParams,
146) -> Result<models::Component, Error<CreateComponentError>> {
147    // unbox the parameters
148    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
190/// Deletes a component.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the component or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
191pub async fn delete_component(
192    configuration: &configuration::Configuration,
193    params: DeleteComponentParams,
194) -> Result<(), Error<DeleteComponentError>> {
195    // unbox the parameters
196    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
246/// Returns a component.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for project containing the component.
247pub async fn get_component(
248    configuration: &configuration::Configuration,
249    params: GetComponentParams,
250) -> Result<models::Component, Error<GetComponentError>> {
251    // unbox the parameters
252    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
297/// Returns the counts of issues assigned to the component.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
298pub async fn get_component_related_issues(
299    configuration: &configuration::Configuration,
300    params: GetComponentRelatedIssuesParams,
301) -> Result<models::ComponentIssuesCount, Error<GetComponentRelatedIssuesError>> {
302    // unbox the parameters
303    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
348/// Returns all components in a project. See the [Get project components paginated](#api-rest-api-3-project-projectIdOrKey-component-get) resource if you want to get a full list of components with pagination.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
349pub async fn get_project_components(
350    configuration: &configuration::Configuration,
351    params: GetProjectComponentsParams,
352) -> Result<Vec<models::Component>, Error<GetProjectComponentsError>> {
353    // unbox the parameters
354    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
399/// Returns a [paginated](#pagination) list of all components in a project. See the [Get project components](#api-rest-api-3-project-projectIdOrKey-components-get) resource if you want to get a full list of versions without pagination.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project.
400pub async fn get_project_components_paginated(
401    configuration: &configuration::Configuration,
402    params: GetProjectComponentsPaginatedParams,
403) -> Result<models::PageBeanComponentWithIssueCount, Error<GetProjectComponentsPaginatedError>> {
404    // unbox the parameters
405    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
470/// Updates a component. Any fields included in the request are overwritten. If `leadAccountId` is an empty string (\"\") the component lead is removed.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** *Administer projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the component or *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
471pub async fn update_component(
472    configuration: &configuration::Configuration,
473    params: UpdateComponentParams,
474) -> Result<models::Component, Error<UpdateComponentError>> {
475    // unbox the parameters
476    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}