hi_jira2/apis/
issue_comments_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 [`add_comment`]
18#[derive(Clone, Debug, Default)]
19pub struct AddCommentParams {
20    /// The ID or key of the issue.
21    pub issue_id_or_key: String,
22    pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
23    /// Use [expand](#expansion) to include additional information about comments in the response. This parameter accepts `renderedBody`, which returns the comment body rendered in HTML.
24    pub expand: Option<String>
25}
26
27/// struct for passing parameters to the method [`delete_comment`]
28#[derive(Clone, Debug, Default)]
29pub struct DeleteCommentParams {
30    /// The ID or key of the issue.
31    pub issue_id_or_key: String,
32    /// The ID of the comment.
33    pub id: String
34}
35
36/// struct for passing parameters to the method [`get_comment`]
37#[derive(Clone, Debug, Default)]
38pub struct GetCommentParams {
39    /// The ID or key of the issue.
40    pub issue_id_or_key: String,
41    /// The ID of the comment.
42    pub id: String,
43    /// Use [expand](#expansion) to include additional information about comments in the response. This parameter accepts `renderedBody`, which returns the comment body rendered in HTML.
44    pub expand: Option<String>
45}
46
47/// struct for passing parameters to the method [`get_comments`]
48#[derive(Clone, Debug, Default)]
49pub struct GetCommentsParams {
50    /// The ID or key of the issue.
51    pub issue_id_or_key: String,
52    /// The index of the first item to return in a page of results (page offset).
53    pub start_at: Option<i64>,
54    /// The maximum number of items to return per page.
55    pub max_results: Option<i32>,
56    /// [Order](#ordering) the results by a field. Accepts *created* to sort comments by their created date.
57    pub order_by: Option<String>,
58    /// Use [expand](#expansion) to include additional information about comments in the response. This parameter accepts `renderedBody`, which returns the comment body rendered in HTML.
59    pub expand: Option<String>
60}
61
62/// struct for passing parameters to the method [`get_comments_by_ids`]
63#[derive(Clone, Debug, Default)]
64pub struct GetCommentsByIdsParams {
65    /// The list of comment IDs.
66    pub issue_comment_list_request_bean: crate::models::IssueCommentListRequestBean,
67    /// Use [expand](#expansion) to include additional information about comments in the response. This parameter accepts a comma-separated list. Expand options include:   *  `renderedBody` Returns the comment body rendered in HTML.  *  `properties` Returns the comment's properties.
68    pub expand: Option<String>
69}
70
71/// struct for passing parameters to the method [`update_comment`]
72#[derive(Clone, Debug, Default)]
73pub struct UpdateCommentParams {
74    /// The ID or key of the issue.
75    pub issue_id_or_key: String,
76    /// The ID of the comment.
77    pub id: String,
78    pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
79    /// Whether users are notified when a comment is updated.
80    pub notify_users: Option<bool>,
81    /// Use [expand](#expansion) to include additional information about comments in the response. This parameter accepts `renderedBody`, which returns the comment body rendered in HTML.
82    pub expand: Option<String>
83}
84
85
86/// struct for typed errors of method [`add_comment`]
87#[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/// struct for typed errors of method [`delete_comment`]
97#[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/// struct for typed errors of method [`get_comment`]
108#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetCommentError {
111    Status401(),
112    Status404(),
113    UnknownValue(serde_json::Value),
114}
115
116/// struct for typed errors of method [`get_comments`]
117#[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/// struct for typed errors of method [`get_comments_by_ids`]
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[serde(untagged)]
129pub enum GetCommentsByIdsError {
130    Status400(),
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`update_comment`]
135#[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
145/// Adds a comment to an issue.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  *Browse projects* and *Add comments* [ project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue containing the comment is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
146pub async fn add_comment(configuration: &configuration::Configuration, params: AddCommentParams) -> Result<crate::models::Comment, Error<AddCommentError>> {
147    let local_var_configuration = configuration;
148
149    // unbox the parameters
150    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
189/// Deletes a comment.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue containing the comment is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  *Delete all comments*[ project permission](https://confluence.atlassian.com/x/yodKLg) to delete any comment or *Delete own comments* to delete comment created by the user,  *  If the comment has visibility restrictions, the user belongs to the group or has the role visibility is restricted to.
190pub async fn delete_comment(configuration: &configuration::Configuration, params: DeleteCommentParams) -> Result<(), Error<DeleteCommentError>> {
191    let local_var_configuration = configuration;
192
193    // unbox the parameters
194    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
228/// Returns a comment.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the comment.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  If the comment has visibility restrictions, the user belongs to the group or has the role visibility is restricted to.
229pub async fn get_comment(configuration: &configuration::Configuration, params: GetCommentParams) -> Result<crate::models::Comment, Error<GetCommentError>> {
230    let local_var_configuration = configuration;
231
232    // unbox the parameters
233    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
271/// Returns all comments for an issue.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** Comments are included in the response where the user has:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the comment.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  If the comment has visibility restrictions, belongs to the group or has the role visibility is role visibility is restricted to.
272pub async fn get_comments(configuration: &configuration::Configuration, params: GetCommentsParams) -> Result<crate::models::PageOfComments, Error<GetCommentsError>> {
273    let local_var_configuration = configuration;
274
275    // unbox the parameters
276    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
325/// Returns a [paginated](#pagination) list of comments specified by a list of comment IDs.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** Comments are returned where the user:   *  has *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the comment.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  If the comment has visibility restrictions, belongs to the group or has the role visibility is restricted to.
326pub 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    // unbox the parameters
330    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
368/// Updates a comment.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue containing the comment is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  *Edit all comments*[ project permission](https://confluence.atlassian.com/x/yodKLg) to update any comment or *Edit own comments* to update comment created by the user.  *  If the comment has visibility restrictions, the user belongs to the group or has the role visibility is restricted to.
369pub async fn update_comment(configuration: &configuration::Configuration, params: UpdateCommentParams) -> Result<crate::models::Comment, Error<UpdateCommentError>> {
370    let local_var_configuration = configuration;
371
372    // unbox the parameters
373    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