1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct AddCommentParams {
20 pub issue_id_or_key: String,
22 pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
23 pub expand: Option<String>
25}
26
27#[derive(Clone, Debug, Default)]
29pub struct DeleteCommentParams {
30 pub issue_id_or_key: String,
32 pub id: String
34}
35
36#[derive(Clone, Debug, Default)]
38pub struct GetCommentParams {
39 pub issue_id_or_key: String,
41 pub id: String,
43 pub expand: Option<String>
45}
46
47#[derive(Clone, Debug, Default)]
49pub struct GetCommentsParams {
50 pub issue_id_or_key: String,
52 pub start_at: Option<i64>,
54 pub max_results: Option<i32>,
56 pub order_by: Option<String>,
58 pub expand: Option<String>
60}
61
62#[derive(Clone, Debug, Default)]
64pub struct GetCommentsByIdsParams {
65 pub issue_comment_list_request_bean: crate::models::IssueCommentListRequestBean,
67 pub expand: Option<String>
69}
70
71#[derive(Clone, Debug, Default)]
73pub struct UpdateCommentParams {
74 pub issue_id_or_key: String,
76 pub id: String,
78 pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
79 pub notify_users: Option<bool>,
81 pub expand: Option<String>
83}
84
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88#[serde(untagged)]
89pub enum AddCommentError {
90 Status400(),
91 Status401(),
92 Status404(),
93 UnknownValue(serde_json::Value),
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum DeleteCommentError {
100 Status400(),
101 Status401(),
102 Status404(),
103 Status405(),
104 UnknownValue(serde_json::Value),
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetCommentError {
111 Status401(),
112 Status404(),
113 UnknownValue(serde_json::Value),
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum GetCommentsError {
120 Status400(),
121 Status401(),
122 Status404(),
123 UnknownValue(serde_json::Value),
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum GetCommentsByIdsError {
130 Status400(),
131 UnknownValue(serde_json::Value),
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum UpdateCommentError {
138 Status400(),
139 Status401(),
140 Status404(),
141 UnknownValue(serde_json::Value),
142}
143
144
145pub async fn add_comment(configuration: &configuration::Configuration, params: AddCommentParams) -> Result<crate::models::Comment, Error<AddCommentError>> {
147 let local_var_configuration = configuration;
148
149 let issue_id_or_key = params.issue_id_or_key;
151 let request_body = params.request_body;
152 let expand = params.expand;
153
154
155 let local_var_client = &local_var_configuration.client;
156
157 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
158 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
159
160 if let Some(ref local_var_str) = expand {
161 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
162 }
163 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
164 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165 }
166 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
167 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
168 };
169 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
170 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
171 };
172 local_var_req_builder = local_var_req_builder.json(&request_body);
173
174 let local_var_req = local_var_req_builder.build()?;
175 let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177 let local_var_status = local_var_resp.status();
178 let local_var_content = local_var_resp.text().await?;
179
180 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
181 serde_json::from_str(&local_var_content).map_err(Error::from)
182 } else {
183 let local_var_entity: Option<AddCommentError> = serde_json::from_str(&local_var_content).ok();
184 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185 Err(Error::ResponseError(local_var_error))
186 }
187}
188
189pub async fn delete_comment(configuration: &configuration::Configuration, params: DeleteCommentParams) -> Result<(), Error<DeleteCommentError>> {
191 let local_var_configuration = configuration;
192
193 let issue_id_or_key = params.issue_id_or_key;
195 let id = params.id;
196
197
198 let local_var_client = &local_var_configuration.client;
199
200 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key), id=crate::apis::urlencode(id));
201 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
202
203 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205 }
206 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
207 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208 };
209 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
210 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
211 };
212
213 let local_var_req = local_var_req_builder.build()?;
214 let local_var_resp = local_var_client.execute(local_var_req).await?;
215
216 let local_var_status = local_var_resp.status();
217 let local_var_content = local_var_resp.text().await?;
218
219 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
220 Ok(())
221 } else {
222 let local_var_entity: Option<DeleteCommentError> = serde_json::from_str(&local_var_content).ok();
223 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
224 Err(Error::ResponseError(local_var_error))
225 }
226}
227
228pub async fn get_comment(configuration: &configuration::Configuration, params: GetCommentParams) -> Result<crate::models::Comment, Error<GetCommentError>> {
230 let local_var_configuration = configuration;
231
232 let issue_id_or_key = params.issue_id_or_key;
234 let id = params.id;
235 let expand = params.expand;
236
237
238 let local_var_client = &local_var_configuration.client;
239
240 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key), id=crate::apis::urlencode(id));
241 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
242
243 if let Some(ref local_var_str) = expand {
244 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
245 }
246 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
247 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
248 }
249 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
250 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
251 };
252 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
253 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
254 };
255
256 let local_var_req = local_var_req_builder.build()?;
257 let local_var_resp = local_var_client.execute(local_var_req).await?;
258
259 let local_var_status = local_var_resp.status();
260 let local_var_content = local_var_resp.text().await?;
261
262 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
263 serde_json::from_str(&local_var_content).map_err(Error::from)
264 } else {
265 let local_var_entity: Option<GetCommentError> = serde_json::from_str(&local_var_content).ok();
266 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
267 Err(Error::ResponseError(local_var_error))
268 }
269}
270
271pub async fn get_comments(configuration: &configuration::Configuration, params: GetCommentsParams) -> Result<crate::models::PageOfComments, Error<GetCommentsError>> {
273 let local_var_configuration = configuration;
274
275 let issue_id_or_key = params.issue_id_or_key;
277 let start_at = params.start_at;
278 let max_results = params.max_results;
279 let order_by = params.order_by;
280 let expand = params.expand;
281
282
283 let local_var_client = &local_var_configuration.client;
284
285 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
286 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
287
288 if let Some(ref local_var_str) = start_at {
289 local_var_req_builder = local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
290 }
291 if let Some(ref local_var_str) = max_results {
292 local_var_req_builder = local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
293 }
294 if let Some(ref local_var_str) = order_by {
295 local_var_req_builder = local_var_req_builder.query(&[("orderBy", &local_var_str.to_string())]);
296 }
297 if let Some(ref local_var_str) = expand {
298 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
299 }
300 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
301 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
302 }
303 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
304 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
305 };
306 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
307 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
308 };
309
310 let local_var_req = local_var_req_builder.build()?;
311 let local_var_resp = local_var_client.execute(local_var_req).await?;
312
313 let local_var_status = local_var_resp.status();
314 let local_var_content = local_var_resp.text().await?;
315
316 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
317 serde_json::from_str(&local_var_content).map_err(Error::from)
318 } else {
319 let local_var_entity: Option<GetCommentsError> = serde_json::from_str(&local_var_content).ok();
320 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
321 Err(Error::ResponseError(local_var_error))
322 }
323}
324
325pub async fn get_comments_by_ids(configuration: &configuration::Configuration, params: GetCommentsByIdsParams) -> Result<crate::models::PageBeanComment, Error<GetCommentsByIdsError>> {
327 let local_var_configuration = configuration;
328
329 let issue_comment_list_request_bean = params.issue_comment_list_request_bean;
331 let expand = params.expand;
332
333
334 let local_var_client = &local_var_configuration.client;
335
336 let local_var_uri_str = format!("{}/rest/api/2/comment/list", local_var_configuration.base_path);
337 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
338
339 if let Some(ref local_var_str) = expand {
340 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
341 }
342 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
343 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
344 }
345 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
346 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
347 };
348 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
349 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
350 };
351 local_var_req_builder = local_var_req_builder.json(&issue_comment_list_request_bean);
352
353 let local_var_req = local_var_req_builder.build()?;
354 let local_var_resp = local_var_client.execute(local_var_req).await?;
355
356 let local_var_status = local_var_resp.status();
357 let local_var_content = local_var_resp.text().await?;
358
359 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360 serde_json::from_str(&local_var_content).map_err(Error::from)
361 } else {
362 let local_var_entity: Option<GetCommentsByIdsError> = serde_json::from_str(&local_var_content).ok();
363 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
364 Err(Error::ResponseError(local_var_error))
365 }
366}
367
368pub async fn update_comment(configuration: &configuration::Configuration, params: UpdateCommentParams) -> Result<crate::models::Comment, Error<UpdateCommentError>> {
370 let local_var_configuration = configuration;
371
372 let issue_id_or_key = params.issue_id_or_key;
374 let id = params.id;
375 let request_body = params.request_body;
376 let notify_users = params.notify_users;
377 let expand = params.expand;
378
379
380 let local_var_client = &local_var_configuration.client;
381
382 let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key), id=crate::apis::urlencode(id));
383 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
384
385 if let Some(ref local_var_str) = notify_users {
386 local_var_req_builder = local_var_req_builder.query(&[("notifyUsers", &local_var_str.to_string())]);
387 }
388 if let Some(ref local_var_str) = expand {
389 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
390 }
391 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
392 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
393 }
394 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
395 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
396 };
397 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
398 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
399 };
400 local_var_req_builder = local_var_req_builder.json(&request_body);
401
402 let local_var_req = local_var_req_builder.build()?;
403 let local_var_resp = local_var_client.execute(local_var_req).await?;
404
405 let local_var_status = local_var_resp.status();
406 let local_var_content = local_var_resp.text().await?;
407
408 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
409 serde_json::from_str(&local_var_content).map_err(Error::from)
410 } else {
411 let local_var_entity: Option<UpdateCommentError> = serde_json::from_str(&local_var_content).ok();
412 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
413 Err(Error::ResponseError(local_var_error))
414 }
415}
416