jira2/apis/
issue_votes_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;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`add_vote`]
18#[derive(Clone, Debug, Default)]
19pub struct AddVoteParams {
20    /// The ID or key of the issue.
21    pub issue_id_or_key: String
22}
23
24/// struct for passing parameters to the method [`get_votes`]
25#[derive(Clone, Debug, Default)]
26pub struct GetVotesParams {
27    /// The ID or key of the issue.
28    pub issue_id_or_key: String
29}
30
31/// struct for passing parameters to the method [`remove_vote`]
32#[derive(Clone, Debug, Default)]
33pub struct RemoveVoteParams {
34    /// The ID or key of the issue.
35    pub issue_id_or_key: String
36}
37
38
39/// struct for typed errors of method [`add_vote`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum AddVoteError {
43    Status401(),
44    Status404(),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_votes`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetVotesError {
52    Status401(),
53    Status404(),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`remove_vote`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum RemoveVoteError {
61    Status401(),
62    Status404(),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Adds the user's vote to an issue. This is the equivalent of the user clicking *Vote* on an issue in Jira.  This operation requires the **Allow users to vote on 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.
68pub async fn add_vote(configuration: &configuration::Configuration, params: AddVoteParams) -> Result<serde_json::Value, Error<AddVoteError>> {
69    let local_var_configuration = configuration;
70
71    // unbox the parameters
72    let issue_id_or_key = params.issue_id_or_key;
73
74
75    let local_var_client = &local_var_configuration.client;
76
77    let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
78    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82    }
83    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
84        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85    };
86    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
87        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
88    };
89
90    let local_var_req = local_var_req_builder.build()?;
91    let local_var_resp = local_var_client.execute(local_var_req).await?;
92
93    let local_var_status = local_var_resp.status();
94    let local_var_content = local_var_resp.text().await?;
95
96    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97        serde_json::from_str(&local_var_content).map_err(Error::from)
98    } else {
99        let local_var_entity: Option<AddVoteError> = serde_json::from_str(&local_var_content).ok();
100        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
101        Err(Error::ResponseError(local_var_error))
102    }
103}
104
105/// Returns details about the votes on an issue.  This operation requires the **Allow users to vote on 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.  Note that users with the necessary permissions for this operation but without the *View voters and watchers* project permissions are not returned details in the `voters` field.
106pub async fn get_votes(configuration: &configuration::Configuration, params: GetVotesParams) -> Result<crate::models::Votes, Error<GetVotesError>> {
107    let local_var_configuration = configuration;
108
109    // unbox the parameters
110    let issue_id_or_key = params.issue_id_or_key;
111
112
113    let local_var_client = &local_var_configuration.client;
114
115    let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
116    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
117
118    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
119        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
120    }
121    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
122        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
123    };
124    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
125        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
126    };
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        serde_json::from_str(&local_var_content).map_err(Error::from)
136    } else {
137        let local_var_entity: Option<GetVotesError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143/// Deletes a user's vote from an issue. This is the equivalent of the user clicking *Unvote* on an issue in Jira.  This operation requires the **Allow users to vote on 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.
144pub async fn remove_vote(configuration: &configuration::Configuration, params: RemoveVoteParams) -> Result<(), Error<RemoveVoteError>> {
145    let local_var_configuration = configuration;
146
147    // unbox the parameters
148    let issue_id_or_key = params.issue_id_or_key;
149
150
151    let local_var_client = &local_var_configuration.client;
152
153    let local_var_uri_str = format!("{}/rest/api/2/issue/{issueIdOrKey}/votes", local_var_configuration.base_path, issueIdOrKey=crate::apis::urlencode(issue_id_or_key));
154    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
155
156    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
157        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
158    }
159    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
160        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
161    };
162    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
163        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
164    };
165
166    let local_var_req = local_var_req_builder.build()?;
167    let local_var_resp = local_var_client.execute(local_var_req).await?;
168
169    let local_var_status = local_var_resp.status();
170    let local_var_content = local_var_resp.text().await?;
171
172    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173        Ok(())
174    } else {
175        let local_var_entity: Option<RemoveVoteError> = serde_json::from_str(&local_var_content).ok();
176        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
177        Err(Error::ResponseError(local_var_error))
178    }
179}
180