jira_api_v2/apis/
issue_watchers_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_watcher`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddWatcherError {
22    Status400(),
23    Status401(),
24    Status403(),
25    Status404(),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`get_issue_watchers`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum GetIssueWatchersError {
33    Status401(),
34    Status404(),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`remove_watcher`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum RemoveWatcherError {
42    Status400(),
43    Status401(),
44    Status403(),
45    Status404(),
46    UnknownValue(serde_json::Value),
47}
48
49
50/// Adds a user as a watcher of an issue by passing the account ID of the user. For example, `\"5b10ac8d82e05b22cc7d4ef5\"`. If no user is specified the calling user is added.  This operation requires the **Allow users to watch issues** option to be *ON*. This option is set in General configuration for Jira. See [Configuring Jira application options](https://confluence.atlassian.com/x/uYXKM) for details.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  To add users other than themselves to the watchlist, *Manage watcher list* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
51pub async fn add_watcher(configuration: &configuration::Configuration, issue_id_or_key: &str, body: &str) -> Result<serde_json::Value, Error<AddWatcherError>> {
52    // add a prefix to parameters to efficiently prevent name collisions
53    let p_issue_id_or_key = issue_id_or_key;
54    let p_body = body;
55
56    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/watchers", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
57    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
58
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62    if let Some(ref token) = configuration.oauth_access_token {
63        req_builder = req_builder.bearer_auth(token.to_owned());
64    };
65    if let Some(ref auth_conf) = configuration.basic_auth {
66        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
67    };
68    req_builder = req_builder.json(&p_body);
69
70    let req = req_builder.build()?;
71    let resp = configuration.client.execute(req).await?;
72
73    let status = resp.status();
74
75    if !status.is_client_error() && !status.is_server_error() {
76        let content = resp.text().await?;
77        serde_json::from_str(&content).map_err(Error::from)
78    } else {
79        let content = resp.text().await?;
80        let entity: Option<AddWatcherError> = serde_json::from_str(&content).ok();
81        Err(Error::ResponseError(ResponseContent { status, content, entity }))
82    }
83}
84
85/// Returns the watchers for an issue.  This operation requires the **Allow users to watch issues** option to be *ON*. This option is set in General configuration for Jira. See [Configuring Jira application options](https://confluence.atlassian.com/x/uYXKM) for details.  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 is ini  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  To see details of users on the watchlist other than themselves, *View voters and watchers* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
86pub async fn get_issue_watchers(configuration: &configuration::Configuration, issue_id_or_key: &str) -> Result<models::Watchers, Error<GetIssueWatchersError>> {
87    // add a prefix to parameters to efficiently prevent name collisions
88    let p_issue_id_or_key = issue_id_or_key;
89
90    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/watchers", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
91    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    if let Some(ref token) = configuration.oauth_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99    if let Some(ref auth_conf) = configuration.basic_auth {
100        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
101    };
102
103    let req = req_builder.build()?;
104    let resp = configuration.client.execute(req).await?;
105
106    let status = resp.status();
107
108    if !status.is_client_error() && !status.is_server_error() {
109        let content = resp.text().await?;
110        serde_json::from_str(&content).map_err(Error::from)
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<GetIssueWatchersError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
115    }
116}
117
118/// Deletes a user as a watcher of an issue.  This operation requires the **Allow users to watch issues** option to be *ON*. This option is set in General configuration for Jira. See [Configuring Jira application options](https://confluence.atlassian.com/x/uYXKM) for details.  **[Permissions](#permissions) required:**   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.  *  To remove users other than themselves from the watchlist, *Manage watcher list* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
119pub async fn remove_watcher(configuration: &configuration::Configuration, issue_id_or_key: &str, username: Option<&str>, account_id: Option<&str>) -> Result<(), Error<RemoveWatcherError>> {
120    // add a prefix to parameters to efficiently prevent name collisions
121    let p_issue_id_or_key = issue_id_or_key;
122    let p_username = username;
123    let p_account_id = account_id;
124
125    let uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/watchers", configuration.base_path, issueIdOrKey=crate::apis::urlencode(p_issue_id_or_key));
126    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
127
128    if let Some(ref param_value) = p_username {
129        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
130    }
131    if let Some(ref param_value) = p_account_id {
132        req_builder = req_builder.query(&[("accountId", &param_value.to_string())]);
133    }
134    if let Some(ref user_agent) = configuration.user_agent {
135        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136    }
137    if let Some(ref token) = configuration.oauth_access_token {
138        req_builder = req_builder.bearer_auth(token.to_owned());
139    };
140    if let Some(ref auth_conf) = configuration.basic_auth {
141        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
142    };
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148
149    if !status.is_client_error() && !status.is_server_error() {
150        Ok(())
151    } else {
152        let content = resp.text().await?;
153        let entity: Option<RemoveWatcherError> = serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent { status, content, entity }))
155    }
156}
157