jira_api_v2/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
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_component`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateComponentError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`delete_component`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DeleteComponentError {
33    Status401(),
34    Status403(),
35    Status404(),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_component`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetComponentError {
43    Status401(),
44    Status404(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_component_related_issues`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetComponentRelatedIssuesError {
52    Status401(),
53    Status404(),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`get_project_components`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetProjectComponentsError {
61    Status401(),
62    Status404(),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_project_components_paginated`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetProjectComponentsPaginatedError {
70    Status401(),
71    Status404(),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`update_component`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum UpdateComponentError {
79    Status400(),
80    Status401(),
81    Status403(),
82    Status404(),
83    UnknownValue(serde_json::Value),
84}
85
86
87/// 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).
88pub async fn create_component(configuration: &configuration::Configuration, component: models::Component) -> Result<models::Component, Error<CreateComponentError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_component = component;
91
92    let uri_str = format!("{}/rest/api/2/component", configuration.base_path);
93    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
94
95    if let Some(ref user_agent) = configuration.user_agent {
96        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97    }
98    if let Some(ref token) = configuration.oauth_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101    if let Some(ref auth_conf) = configuration.basic_auth {
102        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
103    };
104    req_builder = req_builder.json(&p_component);
105
106    let req = req_builder.build()?;
107    let resp = configuration.client.execute(req).await?;
108
109    let status = resp.status();
110
111    if !status.is_client_error() && !status.is_server_error() {
112        let content = resp.text().await?;
113        serde_json::from_str(&content).map_err(Error::from)
114    } else {
115        let content = resp.text().await?;
116        let entity: Option<CreateComponentError> = serde_json::from_str(&content).ok();
117        Err(Error::ResponseError(ResponseContent { status, content, entity }))
118    }
119}
120
121/// 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).
122pub async fn delete_component(configuration: &configuration::Configuration, id: &str, move_issues_to: Option<&str>) -> Result<(), Error<DeleteComponentError>> {
123    // add a prefix to parameters to efficiently prevent name collisions
124    let p_id = id;
125    let p_move_issues_to = move_issues_to;
126
127    let uri_str = format!("{}/rest/api/2/component/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
128    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
129
130    if let Some(ref param_value) = p_move_issues_to {
131        req_builder = req_builder.query(&[("moveIssuesTo", &param_value.to_string())]);
132    }
133    if let Some(ref user_agent) = configuration.user_agent {
134        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135    }
136    if let Some(ref token) = configuration.oauth_access_token {
137        req_builder = req_builder.bearer_auth(token.to_owned());
138    };
139    if let Some(ref auth_conf) = configuration.basic_auth {
140        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
141    };
142
143    let req = req_builder.build()?;
144    let resp = configuration.client.execute(req).await?;
145
146    let status = resp.status();
147
148    if !status.is_client_error() && !status.is_server_error() {
149        Ok(())
150    } else {
151        let content = resp.text().await?;
152        let entity: Option<DeleteComponentError> = serde_json::from_str(&content).ok();
153        Err(Error::ResponseError(ResponseContent { status, content, entity }))
154    }
155}
156
157/// 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.
158pub async fn get_component(configuration: &configuration::Configuration, id: &str) -> Result<models::Component, Error<GetComponentError>> {
159    // add a prefix to parameters to efficiently prevent name collisions
160    let p_id = id;
161
162    let uri_str = format!("{}/rest/api/2/component/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
163    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
164
165    if let Some(ref user_agent) = configuration.user_agent {
166        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
167    }
168    if let Some(ref token) = configuration.oauth_access_token {
169        req_builder = req_builder.bearer_auth(token.to_owned());
170    };
171    if let Some(ref auth_conf) = configuration.basic_auth {
172        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
173    };
174
175    let req = req_builder.build()?;
176    let resp = configuration.client.execute(req).await?;
177
178    let status = resp.status();
179
180    if !status.is_client_error() && !status.is_server_error() {
181        let content = resp.text().await?;
182        serde_json::from_str(&content).map_err(Error::from)
183    } else {
184        let content = resp.text().await?;
185        let entity: Option<GetComponentError> = serde_json::from_str(&content).ok();
186        Err(Error::ResponseError(ResponseContent { status, content, entity }))
187    }
188}
189
190/// Returns the counts of issues assigned to the component.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
191pub async fn get_component_related_issues(configuration: &configuration::Configuration, id: &str) -> Result<models::ComponentIssuesCount, Error<GetComponentRelatedIssuesError>> {
192    // add a prefix to parameters to efficiently prevent name collisions
193    let p_id = id;
194
195    let uri_str = format!("{}/rest/api/2/component/{id}/relatedIssueCounts", configuration.base_path, id=crate::apis::urlencode(p_id));
196    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
197
198    if let Some(ref user_agent) = configuration.user_agent {
199        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
200    }
201    if let Some(ref token) = configuration.oauth_access_token {
202        req_builder = req_builder.bearer_auth(token.to_owned());
203    };
204    if let Some(ref auth_conf) = configuration.basic_auth {
205        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
206    };
207
208    let req = req_builder.build()?;
209    let resp = configuration.client.execute(req).await?;
210
211    let status = resp.status();
212
213    if !status.is_client_error() && !status.is_server_error() {
214        let content = resp.text().await?;
215        serde_json::from_str(&content).map_err(Error::from)
216    } else {
217        let content = resp.text().await?;
218        let entity: Option<GetComponentRelatedIssuesError> = serde_json::from_str(&content).ok();
219        Err(Error::ResponseError(ResponseContent { status, content, entity }))
220    }
221}
222
223/// Returns all components in a project. See the [Get project components paginated](#api-rest-api-2-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.
224pub async fn get_project_components(configuration: &configuration::Configuration, project_id_or_key: &str) -> Result<Vec<models::Component>, Error<GetProjectComponentsError>> {
225    // add a prefix to parameters to efficiently prevent name collisions
226    let p_project_id_or_key = project_id_or_key;
227
228    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/components", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
229    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231    if let Some(ref user_agent) = configuration.user_agent {
232        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233    }
234    if let Some(ref token) = configuration.oauth_access_token {
235        req_builder = req_builder.bearer_auth(token.to_owned());
236    };
237    if let Some(ref auth_conf) = configuration.basic_auth {
238        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
239    };
240
241    let req = req_builder.build()?;
242    let resp = configuration.client.execute(req).await?;
243
244    let status = resp.status();
245
246    if !status.is_client_error() && !status.is_server_error() {
247        let content = resp.text().await?;
248        serde_json::from_str(&content).map_err(Error::from)
249    } else {
250        let content = resp.text().await?;
251        let entity: Option<GetProjectComponentsError> = serde_json::from_str(&content).ok();
252        Err(Error::ResponseError(ResponseContent { status, content, entity }))
253    }
254}
255
256/// Returns a [paginated](#pagination) list of all components in a project. See the [Get project components](#api-rest-api-2-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.
257pub async fn get_project_components_paginated(configuration: &configuration::Configuration, project_id_or_key: &str, start_at: Option<i64>, max_results: Option<i32>, order_by: Option<&str>, query: Option<&str>) -> Result<models::PageBeanComponentWithIssueCount, Error<GetProjectComponentsPaginatedError>> {
258    // add a prefix to parameters to efficiently prevent name collisions
259    let p_project_id_or_key = project_id_or_key;
260    let p_start_at = start_at;
261    let p_max_results = max_results;
262    let p_order_by = order_by;
263    let p_query = query;
264
265    let uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/component", configuration.base_path, projectIdOrKey=crate::apis::urlencode(p_project_id_or_key));
266    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
267
268    if let Some(ref param_value) = p_start_at {
269        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
270    }
271    if let Some(ref param_value) = p_max_results {
272        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
273    }
274    if let Some(ref param_value) = p_order_by {
275        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
276    }
277    if let Some(ref param_value) = p_query {
278        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
279    }
280    if let Some(ref user_agent) = configuration.user_agent {
281        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
282    }
283    if let Some(ref token) = configuration.oauth_access_token {
284        req_builder = req_builder.bearer_auth(token.to_owned());
285    };
286    if let Some(ref auth_conf) = configuration.basic_auth {
287        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
288    };
289
290    let req = req_builder.build()?;
291    let resp = configuration.client.execute(req).await?;
292
293    let status = resp.status();
294
295    if !status.is_client_error() && !status.is_server_error() {
296        let content = resp.text().await?;
297        serde_json::from_str(&content).map_err(Error::from)
298    } else {
299        let content = resp.text().await?;
300        let entity: Option<GetProjectComponentsPaginatedError> = serde_json::from_str(&content).ok();
301        Err(Error::ResponseError(ResponseContent { status, content, entity }))
302    }
303}
304
305/// 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).
306pub async fn update_component(configuration: &configuration::Configuration, id: &str, component: models::Component) -> Result<models::Component, Error<UpdateComponentError>> {
307    // add a prefix to parameters to efficiently prevent name collisions
308    let p_id = id;
309    let p_component = component;
310
311    let uri_str = format!("{}/rest/api/2/component/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
312    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
313
314    if let Some(ref user_agent) = configuration.user_agent {
315        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316    }
317    if let Some(ref token) = configuration.oauth_access_token {
318        req_builder = req_builder.bearer_auth(token.to_owned());
319    };
320    if let Some(ref auth_conf) = configuration.basic_auth {
321        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
322    };
323    req_builder = req_builder.json(&p_component);
324
325    let req = req_builder.build()?;
326    let resp = configuration.client.execute(req).await?;
327
328    let status = resp.status();
329
330    if !status.is_client_error() && !status.is_server_error() {
331        let content = resp.text().await?;
332        serde_json::from_str(&content).map_err(Error::from)
333    } else {
334        let content = resp.text().await?;
335        let entity: Option<UpdateComponentError> = serde_json::from_str(&content).ok();
336        Err(Error::ResponseError(ResponseContent { status, content, entity }))
337    }
338}
339