jira_api_v2/apis/
project_categories_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_project_category`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateProjectCategoryError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status409(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_all_project_categories`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetAllProjectCategoriesError {
33    Status401(),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`get_project_category_by_id`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetProjectCategoryByIdError {
41    Status401(),
42    Status404(),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`remove_project_category`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum RemoveProjectCategoryError {
50    Status401(),
51    Status403(),
52    Status404(),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`update_project_category`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum UpdateProjectCategoryError {
60    Status400(),
61    Status401(),
62    Status403(),
63    Status404(),
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Creates a project category.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
69pub async fn create_project_category(configuration: &configuration::Configuration, project_category: models::ProjectCategory) -> Result<models::ProjectCategory, Error<CreateProjectCategoryError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_project_category = project_category;
72
73    let uri_str = format!("{}/rest/api/2/projectCategory", configuration.base_path);
74    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
75
76    if let Some(ref user_agent) = configuration.user_agent {
77        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78    }
79    if let Some(ref token) = configuration.oauth_access_token {
80        req_builder = req_builder.bearer_auth(token.to_owned());
81    };
82    if let Some(ref auth_conf) = configuration.basic_auth {
83        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
84    };
85    req_builder = req_builder.json(&p_project_category);
86
87    let req = req_builder.build()?;
88    let resp = configuration.client.execute(req).await?;
89
90    let status = resp.status();
91
92    if !status.is_client_error() && !status.is_server_error() {
93        let content = resp.text().await?;
94        serde_json::from_str(&content).map_err(Error::from)
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<CreateProjectCategoryError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent { status, content, entity }))
99    }
100}
101
102/// Returns all project categories.  **[Permissions](#permissions) required:** Permission to access Jira.
103pub async fn get_all_project_categories(configuration: &configuration::Configuration, ) -> Result<Vec<models::ProjectCategory>, Error<GetAllProjectCategoriesError>> {
104
105    let uri_str = format!("{}/rest/api/2/projectCategory", configuration.base_path);
106    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
107
108    if let Some(ref user_agent) = configuration.user_agent {
109        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110    }
111    if let Some(ref token) = configuration.oauth_access_token {
112        req_builder = req_builder.bearer_auth(token.to_owned());
113    };
114    if let Some(ref auth_conf) = configuration.basic_auth {
115        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
116    };
117
118    let req = req_builder.build()?;
119    let resp = configuration.client.execute(req).await?;
120
121    let status = resp.status();
122
123    if !status.is_client_error() && !status.is_server_error() {
124        let content = resp.text().await?;
125        serde_json::from_str(&content).map_err(Error::from)
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<GetAllProjectCategoriesError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132
133/// Returns a project category.  **[Permissions](#permissions) required:** Permission to access Jira.
134pub async fn get_project_category_by_id(configuration: &configuration::Configuration, id: i64) -> Result<models::ProjectCategory, Error<GetProjectCategoryByIdError>> {
135    // add a prefix to parameters to efficiently prevent name collisions
136    let p_id = id;
137
138    let uri_str = format!("{}/rest/api/2/projectCategory/{id}", configuration.base_path, id=p_id);
139    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
140
141    if let Some(ref user_agent) = configuration.user_agent {
142        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143    }
144    if let Some(ref token) = configuration.oauth_access_token {
145        req_builder = req_builder.bearer_auth(token.to_owned());
146    };
147    if let Some(ref auth_conf) = configuration.basic_auth {
148        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
149    };
150
151    let req = req_builder.build()?;
152    let resp = configuration.client.execute(req).await?;
153
154    let status = resp.status();
155
156    if !status.is_client_error() && !status.is_server_error() {
157        let content = resp.text().await?;
158        serde_json::from_str(&content).map_err(Error::from)
159    } else {
160        let content = resp.text().await?;
161        let entity: Option<GetProjectCategoryByIdError> = serde_json::from_str(&content).ok();
162        Err(Error::ResponseError(ResponseContent { status, content, entity }))
163    }
164}
165
166/// Deletes a project category.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
167pub async fn remove_project_category(configuration: &configuration::Configuration, id: i64) -> Result<(), Error<RemoveProjectCategoryError>> {
168    // add a prefix to parameters to efficiently prevent name collisions
169    let p_id = id;
170
171    let uri_str = format!("{}/rest/api/2/projectCategory/{id}", configuration.base_path, id=p_id);
172    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
173
174    if let Some(ref user_agent) = configuration.user_agent {
175        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176    }
177    if let Some(ref token) = configuration.oauth_access_token {
178        req_builder = req_builder.bearer_auth(token.to_owned());
179    };
180    if let Some(ref auth_conf) = configuration.basic_auth {
181        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
182    };
183
184    let req = req_builder.build()?;
185    let resp = configuration.client.execute(req).await?;
186
187    let status = resp.status();
188
189    if !status.is_client_error() && !status.is_server_error() {
190        Ok(())
191    } else {
192        let content = resp.text().await?;
193        let entity: Option<RemoveProjectCategoryError> = serde_json::from_str(&content).ok();
194        Err(Error::ResponseError(ResponseContent { status, content, entity }))
195    }
196}
197
198/// Updates a project category.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
199pub async fn update_project_category(configuration: &configuration::Configuration, id: i64, project_category: models::ProjectCategory) -> Result<models::UpdatedProjectCategory, Error<UpdateProjectCategoryError>> {
200    // add a prefix to parameters to efficiently prevent name collisions
201    let p_id = id;
202    let p_project_category = project_category;
203
204    let uri_str = format!("{}/rest/api/2/projectCategory/{id}", configuration.base_path, id=p_id);
205    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
206
207    if let Some(ref user_agent) = configuration.user_agent {
208        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
209    }
210    if let Some(ref token) = configuration.oauth_access_token {
211        req_builder = req_builder.bearer_auth(token.to_owned());
212    };
213    if let Some(ref auth_conf) = configuration.basic_auth {
214        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
215    };
216    req_builder = req_builder.json(&p_project_category);
217
218    let req = req_builder.build()?;
219    let resp = configuration.client.execute(req).await?;
220
221    let status = resp.status();
222
223    if !status.is_client_error() && !status.is_server_error() {
224        let content = resp.text().await?;
225        serde_json::from_str(&content).map_err(Error::from)
226    } else {
227        let content = resp.text().await?;
228        let entity: Option<UpdateProjectCategoryError> = serde_json::from_str(&content).ok();
229        Err(Error::ResponseError(ResponseContent { status, content, entity }))
230    }
231}
232