/*
* 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 [`get_workflow_transition_rule_configurations`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetWorkflowTransitionRuleConfigurationsError {
Status400(models::ErrorCollection),
Status403(models::ErrorCollection),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_workflow_transition_rule_configurations`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateWorkflowTransitionRuleConfigurationsError {
Status400(models::ErrorCollection),
Status403(models::ErrorCollection),
UnknownValue(serde_json::Value),
}
/// Returns a [paginated](#pagination) list of workflows with transition rules. The workflows can be filtered to return only those containing workflow transition rules: * of one or more transition rule types, such as [workflow post functions](https://developer.atlassian.com/cloud/jira/platform/modules/workflow-post-function/). * matching one or more transition rule keys. Only workflows containing transition rules created by the calling Connect app are returned. However, if a workflow is returned all transition rules that match the filters are returned for that workflow. Due to server-side optimizations, workflows with an empty list of rules may be returned; these workflows can be ignored. **[Permissions](#permissions) required:** Only Connect apps can use this operation.
pub async fn get_workflow_transition_rule_configurations(configuration: &configuration::Configuration, types: Vec<String>, start_at: Option<i64>, max_results: Option<i32>, keys: Option<Vec<String>>, expand: Option<&str>) -> Result<models::PageBeanWorkflowTransitionRules, Error<GetWorkflowTransitionRuleConfigurationsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_types = types;
let p_start_at = start_at;
let p_max_results = max_results;
let p_keys = keys;
let p_expand = expand;
let uri_str = format!("{}/rest/api/2/workflow/rule/config", configuration.base_path);
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())]);
}
req_builder = match "multi" {
"multi" => req_builder.query(&p_types.into_iter().map(|p| ("types".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("types", &p_types.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
if let Some(ref param_value) = p_keys {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("keys".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("keys", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").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 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<GetWorkflowTransitionRuleConfigurationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Updates configuration of workflow transition rules. The following rule types are supported: * [post functions](https://developer.atlassian.com/cloud/jira/platform/modules/workflow-post-function/) * [conditions](https://developer.atlassian.com/cloud/jira/platform/modules/workflow-condition/) * [validators](https://developer.atlassian.com/cloud/jira/platform/modules/workflow-validator/) Only rules created by the calling Connect app can be updated. **[Permissions](#permissions) required:** Only Connect apps can use this operation.
pub async fn update_workflow_transition_rule_configurations(configuration: &configuration::Configuration, workflow_transition_rules_update: models::WorkflowTransitionRulesUpdate) -> Result<models::WorkflowTransitionRulesUpdateErrors, Error<UpdateWorkflowTransitionRuleConfigurationsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_workflow_transition_rules_update = workflow_transition_rules_update;
let uri_str = format!("{}/rest/api/2/workflow/rule/config", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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 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_workflow_transition_rules_update);
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<UpdateWorkflowTransitionRuleConfigurationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}