hi_jira2/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;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`create_component`]
18#[derive(Clone, Debug, Default)]
19pub struct CreateComponentParams {
20    pub project_component: crate::models::ProjectComponent
21}
22
23/// struct for passing parameters to the method [`delete_component`]
24#[derive(Clone, Debug, Default)]
25pub struct DeleteComponentParams {
26    /// The ID of the component.
27    pub id: String,
28    /// The ID of the component to replace the deleted component. If this value is null no replacement is made.
29    pub move_issues_to: Option<String>
30}
31
32/// struct for passing parameters to the method [`get_component`]
33#[derive(Clone, Debug, Default)]
34pub struct GetComponentParams {
35    /// The ID of the component.
36    pub id: String
37}
38
39/// struct for passing parameters to the method [`get_component_related_issues`]
40#[derive(Clone, Debug, Default)]
41pub struct GetComponentRelatedIssuesParams {
42    /// The ID of the component.
43    pub id: String
44}
45
46/// struct for passing parameters to the method [`get_project_components`]
47#[derive(Clone, Debug, Default)]
48pub struct GetProjectComponentsParams {
49    /// The project ID or project key (case sensitive).
50    pub project_id_or_key: String
51}
52
53/// struct for passing parameters to the method [`get_project_components_paginated`]
54#[derive(Clone, Debug, Default)]
55pub struct GetProjectComponentsPaginatedParams {
56    /// The project ID or project key (case sensitive).
57    pub project_id_or_key: String,
58    /// The index of the first item to return in a page of results (page offset).
59    pub start_at: Option<i64>,
60    /// The maximum number of items to return per page.
61    pub max_results: Option<i32>,
62    /// [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.
63    pub order_by: Option<String>,
64    /// Filter the results using a literal string. Components with a matching `name` or `description` are returned (case insensitive).
65    pub query: Option<String>
66}
67
68/// struct for passing parameters to the method [`update_component`]
69#[derive(Clone, Debug, Default)]
70pub struct UpdateComponentParams {
71    /// The ID of the component.
72    pub id: String,
73    pub project_component: crate::models::ProjectComponent
74}
75
76
77/// struct for typed errors of method [`create_component`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum CreateComponentError {
81    Status400(),
82    Status401(),
83    Status403(),
84    Status404(),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`delete_component`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum DeleteComponentError {
92    Status401(),
93    Status403(),
94    Status404(),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`get_component`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetComponentError {
102    Status401(),
103    Status404(),
104    UnknownValue(serde_json::Value),
105}
106
107/// struct for typed errors of method [`get_component_related_issues`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetComponentRelatedIssuesError {
111    Status401(),
112    Status404(),
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`get_project_components`]
117#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum GetProjectComponentsError {
120    Status401(),
121    Status404(),
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`get_project_components_paginated`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum GetProjectComponentsPaginatedError {
129    Status401(),
130    Status404(),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`update_component`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum UpdateComponentError {
138    Status400(),
139    Status401(),
140    Status403(),
141    Status404(),
142    UnknownValue(serde_json::Value),
143}
144
145
146/// 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).
147pub async fn create_component(configuration: &configuration::Configuration, params: CreateComponentParams) -> Result<crate::models::ProjectComponent, Error<CreateComponentError>> {
148    let local_var_configuration = configuration;
149
150    // unbox the parameters
151    let project_component = params.project_component;
152
153
154    let local_var_client = &local_var_configuration.client;
155
156    let local_var_uri_str = format!("{}/rest/api/2/component", local_var_configuration.base_path);
157    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
158
159    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
160        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
161    }
162    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
163        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
164    };
165    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
166        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
167    };
168    local_var_req_builder = local_var_req_builder.json(&project_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> = serde_json::from_str(&local_var_content).ok();
180        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
181        Err(Error::ResponseError(local_var_error))
182    }
183}
184
185/// 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).
186pub async fn delete_component(configuration: &configuration::Configuration, params: DeleteComponentParams) -> Result<(), Error<DeleteComponentError>> {
187    let local_var_configuration = configuration;
188
189    // unbox the parameters
190    let id = params.id;
191    let move_issues_to = params.move_issues_to;
192
193
194    let local_var_client = &local_var_configuration.client;
195
196    let local_var_uri_str = format!("{}/rest/api/2/component/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
197    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
198
199    if let Some(ref local_var_str) = move_issues_to {
200        local_var_req_builder = local_var_req_builder.query(&[("moveIssuesTo", &local_var_str.to_string())]);
201    }
202    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
203        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
204    }
205    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
206        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
207    };
208    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
209        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
210    };
211
212    let local_var_req = local_var_req_builder.build()?;
213    let local_var_resp = local_var_client.execute(local_var_req).await?;
214
215    let local_var_status = local_var_resp.status();
216    let local_var_content = local_var_resp.text().await?;
217
218    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
219        Ok(())
220    } else {
221        let local_var_entity: Option<DeleteComponentError> = serde_json::from_str(&local_var_content).ok();
222        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
223        Err(Error::ResponseError(local_var_error))
224    }
225}
226
227/// 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.
228pub async fn get_component(configuration: &configuration::Configuration, params: GetComponentParams) -> Result<crate::models::ProjectComponent, Error<GetComponentError>> {
229    let local_var_configuration = configuration;
230
231    // unbox the parameters
232    let id = params.id;
233
234
235    let local_var_client = &local_var_configuration.client;
236
237    let local_var_uri_str = format!("{}/rest/api/2/component/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
238    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
239
240    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
241        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242    }
243    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
244        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
245    };
246    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
247        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
248    };
249
250    let local_var_req = local_var_req_builder.build()?;
251    let local_var_resp = local_var_client.execute(local_var_req).await?;
252
253    let local_var_status = local_var_resp.status();
254    let local_var_content = local_var_resp.text().await?;
255
256    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
257        serde_json::from_str(&local_var_content).map_err(Error::from)
258    } else {
259        let local_var_entity: Option<GetComponentError> = serde_json::from_str(&local_var_content).ok();
260        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
261        Err(Error::ResponseError(local_var_error))
262    }
263}
264
265/// Returns the counts of issues assigned to the component.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
266pub async fn get_component_related_issues(configuration: &configuration::Configuration, params: GetComponentRelatedIssuesParams) -> Result<crate::models::ComponentIssuesCount, Error<GetComponentRelatedIssuesError>> {
267    let local_var_configuration = configuration;
268
269    // unbox the parameters
270    let id = params.id;
271
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/rest/api/2/component/{id}/relatedIssueCounts", local_var_configuration.base_path, id=crate::apis::urlencode(id));
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
282        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283    };
284    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
285        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
286    };
287
288    let local_var_req = local_var_req_builder.build()?;
289    let local_var_resp = local_var_client.execute(local_var_req).await?;
290
291    let local_var_status = local_var_resp.status();
292    let local_var_content = local_var_resp.text().await?;
293
294    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
295        serde_json::from_str(&local_var_content).map_err(Error::from)
296    } else {
297        let local_var_entity: Option<GetComponentRelatedIssuesError> = serde_json::from_str(&local_var_content).ok();
298        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
299        Err(Error::ResponseError(local_var_error))
300    }
301}
302
303/// 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.
304pub async fn get_project_components(configuration: &configuration::Configuration, params: GetProjectComponentsParams) -> Result<Vec<crate::models::ProjectComponent>, Error<GetProjectComponentsError>> {
305    let local_var_configuration = configuration;
306
307    // unbox the parameters
308    let project_id_or_key = params.project_id_or_key;
309
310
311    let local_var_client = &local_var_configuration.client;
312
313    let local_var_uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/components", local_var_configuration.base_path, projectIdOrKey=crate::apis::urlencode(project_id_or_key));
314    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
315
316    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
317        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
318    }
319    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
320        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
321    };
322    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
323        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
324    };
325
326    let local_var_req = local_var_req_builder.build()?;
327    let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329    let local_var_status = local_var_resp.status();
330    let local_var_content = local_var_resp.text().await?;
331
332    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
333        serde_json::from_str(&local_var_content).map_err(Error::from)
334    } else {
335        let local_var_entity: Option<GetProjectComponentsError> = serde_json::from_str(&local_var_content).ok();
336        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
337        Err(Error::ResponseError(local_var_error))
338    }
339}
340
341/// 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.
342pub async fn get_project_components_paginated(configuration: &configuration::Configuration, params: GetProjectComponentsPaginatedParams) -> Result<crate::models::PageBeanComponentWithIssueCount, Error<GetProjectComponentsPaginatedError>> {
343    let local_var_configuration = configuration;
344
345    // unbox the parameters
346    let project_id_or_key = params.project_id_or_key;
347    let start_at = params.start_at;
348    let max_results = params.max_results;
349    let order_by = params.order_by;
350    let query = params.query;
351
352
353    let local_var_client = &local_var_configuration.client;
354
355    let local_var_uri_str = format!("{}/rest/api/2/project/{projectIdOrKey}/component", local_var_configuration.base_path, projectIdOrKey=crate::apis::urlencode(project_id_or_key));
356    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
357
358    if let Some(ref local_var_str) = start_at {
359        local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
360    }
361    if let Some(ref local_var_str) = max_results {
362        local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
363    }
364    if let Some(ref local_var_str) = order_by {
365        local_var_req_builder = local_var_req_builder.query(&[("orderBy", &local_var_str.to_string())]);
366    }
367    if let Some(ref local_var_str) = query {
368        local_var_req_builder = local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
369    }
370    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
371        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
372    }
373    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
374        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
375    };
376    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
377        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
378    };
379
380    let local_var_req = local_var_req_builder.build()?;
381    let local_var_resp = local_var_client.execute(local_var_req).await?;
382
383    let local_var_status = local_var_resp.status();
384    let local_var_content = local_var_resp.text().await?;
385
386    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
387        serde_json::from_str(&local_var_content).map_err(Error::from)
388    } else {
389        let local_var_entity: Option<GetProjectComponentsPaginatedError> = serde_json::from_str(&local_var_content).ok();
390        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
391        Err(Error::ResponseError(local_var_error))
392    }
393}
394
395/// 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).
396pub async fn update_component(configuration: &configuration::Configuration, params: UpdateComponentParams) -> Result<crate::models::ProjectComponent, Error<UpdateComponentError>> {
397    let local_var_configuration = configuration;
398
399    // unbox the parameters
400    let id = params.id;
401    let project_component = params.project_component;
402
403
404    let local_var_client = &local_var_configuration.client;
405
406    let local_var_uri_str = format!("{}/rest/api/2/component/{id}", local_var_configuration.base_path, id=crate::apis::urlencode(id));
407    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
408
409    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
410        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
411    }
412    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
413        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
414    };
415    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
416        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
417    };
418    local_var_req_builder = local_var_req_builder.json(&project_component);
419
420    let local_var_req = local_var_req_builder.build()?;
421    let local_var_resp = local_var_client.execute(local_var_req).await?;
422
423    let local_var_status = local_var_resp.status();
424    let local_var_content = local_var_resp.text().await?;
425
426    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
427        serde_json::from_str(&local_var_content).map_err(Error::from)
428    } else {
429        let local_var_entity: Option<UpdateComponentError> = serde_json::from_str(&local_var_content).ok();
430        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
431        Err(Error::ResponseError(local_var_error))
432    }
433}
434