/*
* The Jira Cloud platform REST API
*
* Jira Cloud platform REST API documentation
*
* The version of the OpenAPI document: 1001.0.0-SNAPSHOT
* Contact: ecosystem@atlassian.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for typed errors of method [`add_comment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddCommentError {
Status400(),
Status401(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_comment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCommentError {
Status400(),
Status401(),
Status404(),
Status405(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_comment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCommentError {
Status401(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_comments`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCommentsError {
Status400(),
Status401(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_comments_by_ids`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCommentsByIdsError {
Status400(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_comment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateCommentError {
Status400(),
Status401(),
Status404(),
UnknownValue(serde_json::Value),
}
/// 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.
pub async fn add_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, comment: models::Comment, expand: Option<&str>) -> Result<models::Comment, Error<AddCommentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_id_or_key = issue_id_or_key;
let p_comment = comment;
let p_expand = expand;
let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_comment);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<AddCommentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn delete_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, id: &str) -> Result<(), Error<DeleteCommentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_id_or_key = issue_id_or_key;
let p_id = id;
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));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteCommentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn get_comment(configuration: &configuration::Configuration, issue_id_or_key: &str, id: &str, expand: Option<&str>) -> Result<models::Comment, Error<GetCommentError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_id_or_key = issue_id_or_key;
let p_id = id;
let p_expand = expand;
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));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetCommentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_id_or_key = issue_id_or_key;
let p_start_at = start_at;
let p_max_results = max_results;
let p_order_by = order_by;
let p_expand = expand;
let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/comment", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_start_at {
req_builder = req_builder.query(&[("startAt", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_max_results {
req_builder = req_builder.query(&[("maxResults", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetCommentsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn get_comments_by_ids(configuration: &configuration::Configuration, issue_comment_list_request_bean: models::IssueCommentListRequestBean, expand: Option<&str>) -> Result<models::PageBeanComment, Error<GetCommentsByIdsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_comment_list_request_bean = issue_comment_list_request_bean;
let p_expand = expand;
let uri_str = format!("{}/rest/api/2/comment/list", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_issue_comment_list_request_bean);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetCommentsByIdsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issue_id_or_key = issue_id_or_key;
let p_id = id;
let p_comment = comment;
let p_expand = expand;
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));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_comment);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<UpdateCommentError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}