jira_api_v2/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;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`add_comment`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddCommentError {
22    Status400(),
23    Status401(),
24    Status404(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`delete_comment`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteCommentError {
32    Status400(),
33    Status401(),
34    Status404(),
35    Status405(),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_comment`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetCommentError {
43    Status401(),
44    Status404(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_comments`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetCommentsError {
52    Status400(),
53    Status401(),
54    Status404(),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`get_comments_by_ids`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetCommentsByIdsError {
62    Status400(),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`update_comment`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum UpdateCommentError {
70    Status400(),
71    Status401(),
72    Status404(),
73    UnknownValue(serde_json::Value),
74}
75
76
77/// 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.
78pub async fn add_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, comment: models::Comment, expand: Option<&str>) -> Result<models::Comment, Error<AddCommentError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_issue_id_or_key = issue_id_or_key;
81    let p_comment = comment;
82    let p_expand = expand;
83
84    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
85    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
86
87    if let Some(ref param_value) = p_expand {
88        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
89    }
90    if let Some(ref user_agent) = configuration.user_agent {
91        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92    }
93    if let Some(ref token) = configuration.oauth_access_token {
94        req_builder = req_builder.bearer_auth(token.to_owned());
95    };
96    if let Some(ref auth_conf) = configuration.basic_auth {
97        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
98    };
99    req_builder = req_builder.json(&p_comment);
100
101    let req = req_builder.build()?;
102    let resp = configuration.client.execute(req).await?;
103
104    let status = resp.status();
105
106    if !status.is_client_error() && !status.is_server_error() {
107        let content = resp.text().await?;
108        serde_json::from_str(&content).map_err(Error::from)
109    } else {
110        let content = resp.text().await?;
111        let entity: Option<AddCommentError> = serde_json::from_str(&content).ok();
112        Err(Error::ResponseError(ResponseContent { status, content, entity }))
113    }
114}
115
116/// 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.
117pub async fn delete_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, id: &str) -> Result<(), Error<DeleteCommentError>> {
118    // add a prefix to parameters to efficiently prevent name collisions
119    let p_issue_id_or_key = issue_id_or_key;
120    let p_id = id;
121
122    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key), id=crate::apis::urlencode(p_id));
123    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
124
125    if let Some(ref user_agent) = configuration.user_agent {
126        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127    }
128    if let Some(ref token) = configuration.oauth_access_token {
129        req_builder = req_builder.bearer_auth(token.to_owned());
130    };
131    if let Some(ref auth_conf) = configuration.basic_auth {
132        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
133    };
134
135    let req = req_builder.build()?;
136    let resp = configuration.client.execute(req).await?;
137
138    let status = resp.status();
139
140    if !status.is_client_error() && !status.is_server_error() {
141        Ok(())
142    } else {
143        let content = resp.text().await?;
144        let entity: Option<DeleteCommentError> = serde_json::from_str(&content).ok();
145        Err(Error::ResponseError(ResponseContent { status, content, entity }))
146    }
147}
148
149/// 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.
150pub async fn get_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, id: &str, expand: Option<&str>) -> Result<models::Comment, Error<GetCommentError>> {
151    // add a prefix to parameters to efficiently prevent name collisions
152    let p_issue_id_or_key = issue_id_or_key;
153    let p_id = id;
154    let p_expand = expand;
155
156    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key), id=crate::apis::urlencode(p_id));
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref param_value) = p_expand {
160        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
161    }
162    if let Some(ref user_agent) = configuration.user_agent {
163        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
164    }
165    if let Some(ref token) = configuration.oauth_access_token {
166        req_builder = req_builder.bearer_auth(token.to_owned());
167    };
168    if let Some(ref auth_conf) = configuration.basic_auth {
169        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
170    };
171
172    let req = req_builder.build()?;
173    let resp = configuration.client.execute(req).await?;
174
175    let status = resp.status();
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        serde_json::from_str(&content).map_err(Error::from)
180    } else {
181        let content = resp.text().await?;
182        let entity: Option<GetCommentError> = serde_json::from_str(&content).ok();
183        Err(Error::ResponseError(ResponseContent { status, content, entity }))
184    }
185}
186
187/// 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.
188pub async fn get_comments(configuration: &configuration::Configuration, issue_id_or_key: &str, start_at: Option<i64>, max_results: Option<i32>, order_by: Option<&str>, expand: Option<&str>) -> Result<models::PageOfComments, Error<GetCommentsError>> {
189    // add a prefix to parameters to efficiently prevent name collisions
190    let p_issue_id_or_key = issue_id_or_key;
191    let p_start_at = start_at;
192    let p_max_results = max_results;
193    let p_order_by = order_by;
194    let p_expand = expand;
195
196    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
197    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
198
199    if let Some(ref param_value) = p_start_at {
200        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
201    }
202    if let Some(ref param_value) = p_max_results {
203        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
204    }
205    if let Some(ref param_value) = p_order_by {
206        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
207    }
208    if let Some(ref param_value) = p_expand {
209        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
210    }
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref token) = configuration.oauth_access_token {
215        req_builder = req_builder.bearer_auth(token.to_owned());
216    };
217    if let Some(ref auth_conf) = configuration.basic_auth {
218        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
219    };
220
221    let req = req_builder.build()?;
222    let resp = configuration.client.execute(req).await?;
223
224    let status = resp.status();
225
226    if !status.is_client_error() && !status.is_server_error() {
227        let content = resp.text().await?;
228        serde_json::from_str(&content).map_err(Error::from)
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<GetCommentsError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent { status, content, entity }))
233    }
234}
235
236/// Returns a [paginated](#pagination) list of just the comments for a list of comments specified by 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.
237pub async fn get_comments_by_ids(configuration: &configuration::Configuration, issue_comment_list_request_bean: models::IssueCommentListRequestBean, expand: Option<&str>) -> Result<models::PageBeanComment, Error<GetCommentsByIdsError>> {
238    // add a prefix to parameters to efficiently prevent name collisions
239    let p_issue_comment_list_request_bean = issue_comment_list_request_bean;
240    let p_expand = expand;
241
242    let uri_str = format!("{}/rest/api/2/comment/list", configuration.base_path);
243    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
244
245    if let Some(ref param_value) = p_expand {
246        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
247    }
248    if let Some(ref user_agent) = configuration.user_agent {
249        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
250    }
251    if let Some(ref token) = configuration.oauth_access_token {
252        req_builder = req_builder.bearer_auth(token.to_owned());
253    };
254    if let Some(ref auth_conf) = configuration.basic_auth {
255        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
256    };
257    req_builder = req_builder.json(&p_issue_comment_list_request_bean);
258
259    let req = req_builder.build()?;
260    let resp = configuration.client.execute(req).await?;
261
262    let status = resp.status();
263
264    if !status.is_client_error() && !status.is_server_error() {
265        let content = resp.text().await?;
266        serde_json::from_str(&content).map_err(Error::from)
267    } else {
268        let content = resp.text().await?;
269        let entity: Option<GetCommentsByIdsError> = serde_json::from_str(&content).ok();
270        Err(Error::ResponseError(ResponseContent { status, content, entity }))
271    }
272}
273
274/// 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.
275pub async fn update_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, id: &str, comment: models::Comment, expand: Option<&str>) -> Result<models::Comment, Error<UpdateCommentError>> {
276    // add a prefix to parameters to efficiently prevent name collisions
277    let p_issue_id_or_key = issue_id_or_key;
278    let p_id = id;
279    let p_comment = comment;
280    let p_expand = expand;
281
282    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment/{id}", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key), id=crate::apis::urlencode(p_id));
283    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
284
285    if let Some(ref param_value) = p_expand {
286        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
287    }
288    if let Some(ref user_agent) = configuration.user_agent {
289        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
290    }
291    if let Some(ref token) = configuration.oauth_access_token {
292        req_builder = req_builder.bearer_auth(token.to_owned());
293    };
294    if let Some(ref auth_conf) = configuration.basic_auth {
295        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
296    };
297    req_builder = req_builder.json(&p_comment);
298
299    let req = req_builder.build()?;
300    let resp = configuration.client.execute(req).await?;
301
302    let status = resp.status();
303
304    if !status.is_client_error() && !status.is_server_error() {
305        let content = resp.text().await?;
306        serde_json::from_str(&content).map_err(Error::from)
307    } else {
308        let content = resp.text().await?;
309        let entity: Option<UpdateCommentError> = serde_json::from_str(&content).ok();
310        Err(Error::ResponseError(ResponseContent { status, content, entity }))
311    }
312}
313