1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[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#[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#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetComponentError {
43 Status401(),
44 Status404(),
45 UnknownValue(serde_json::Value),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetComponentRelatedIssuesError {
52 Status401(),
53 Status404(),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetProjectComponentsError {
61 Status401(),
62 Status404(),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetProjectComponentsPaginatedError {
70 Status401(),
71 Status404(),
72 UnknownValue(serde_json::Value),
73}
74
75#[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
87pub async fn create_component(configuration: &configuration::Configuration, component: models::Component) -> Result<models::Component, Error<CreateComponentError>> {
89 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
121pub async fn delete_component(configuration: &configuration::Configuration, id: &str, move_issues_to: Option<&str>) -> Result<(), Error<DeleteComponentError>> {
123 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", ¶m_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
157pub async fn get_component(configuration: &configuration::Configuration, id: &str) -> Result<models::Component, Error<GetComponentError>> {
159 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
190pub async fn get_component_related_issues(configuration: &configuration::Configuration, id: &str) -> Result<models::ComponentIssuesCount, Error<GetComponentRelatedIssuesError>> {
192 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
223pub async fn get_project_components(configuration: &configuration::Configuration, project_id_or_key: &str) -> Result<Vec<models::Component>, Error<GetProjectComponentsError>> {
225 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
256pub 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 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", ¶m_value.to_string())]);
270 }
271 if let Some(ref param_value) = p_max_results {
272 req_builder = req_builder.query(&[("maxResults", ¶m_value.to_string())]);
273 }
274 if let Some(ref param_value) = p_order_by {
275 req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
276 }
277 if let Some(ref param_value) = p_query {
278 req_builder = req_builder.query(&[("query", ¶m_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
305pub async fn update_component(configuration: &configuration::Configuration, id: &str, component: models::Component) -> Result<models::Component, Error<UpdateComponentError>> {
307 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