jira_api_v2/apis/
workflow_scheme_project_associations_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 [`associate_scheme_with_project`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AssociateSchemeWithProjectError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_workflow_scheme_project_associations`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetWorkflowSchemeProjectAssociationsError {
33    Status400(),
34    Status401(),
35    Status403(),
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Assigns a workflow scheme to a project. This operation is performed only when there are no issues in the project.  Workflow schemes can only be assigned to classic projects.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
41pub async fn associate_scheme_with_project(configuration: &configuration::Configuration, workflow_scheme_project_association: models::WorkflowSchemeProjectAssociation) -> Result<serde_json::Value, Error<AssociateSchemeWithProjectError>> {
42    // add a prefix to parameters to efficiently prevent name collisions
43    let p_workflow_scheme_project_association = workflow_scheme_project_association;
44
45    let uri_str = format!("{}/rest/api/2/workflowscheme/project", configuration.base_path);
46    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
47
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref token) = configuration.oauth_access_token {
52        req_builder = req_builder.bearer_auth(token.to_owned());
53    };
54    if let Some(ref auth_conf) = configuration.basic_auth {
55        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
56    };
57    req_builder = req_builder.json(&p_workflow_scheme_project_association);
58
59    let req = req_builder.build()?;
60    let resp = configuration.client.execute(req).await?;
61
62    let status = resp.status();
63
64    if !status.is_client_error() && !status.is_server_error() {
65        let content = resp.text().await?;
66        serde_json::from_str(&content).map_err(Error::from)
67    } else {
68        let content = resp.text().await?;
69        let entity: Option<AssociateSchemeWithProjectError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent { status, content, entity }))
71    }
72}
73
74/// Returns a list of the workflow schemes associated with a list of projects. Each returned workflow scheme includes a list of the requested projects associated with it. Any next-gen or non-existent projects in the request are ignored and no errors are returned.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
75pub async fn get_workflow_scheme_project_associations(configuration: &configuration::Configuration, project_id: Vec<i64>) -> Result<models::ContainerOfWorkflowSchemeAssociations, Error<GetWorkflowSchemeProjectAssociationsError>> {
76    // add a prefix to parameters to efficiently prevent name collisions
77    let p_project_id = project_id;
78
79    let uri_str = format!("{}/rest/api/2/workflowscheme/project", configuration.base_path);
80    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
81
82    req_builder = match "multi" {
83        "multi" => req_builder.query(&p_project_id.into_iter().map(|p| ("projectId".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
84        _ => req_builder.query(&[("projectId", &p_project_id.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
85    };
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.oauth_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92    if let Some(ref auth_conf) = configuration.basic_auth {
93        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
94    };
95
96    let req = req_builder.build()?;
97    let resp = configuration.client.execute(req).await?;
98
99    let status = resp.status();
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        serde_json::from_str(&content).map_err(Error::from)
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<GetWorkflowSchemeProjectAssociationsError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent { status, content, entity }))
108    }
109}
110