casdoor_sdk/apis/
role_api.rs

1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8/// struct for passing parameters to the method [`add_role`]
9#[derive(Clone, Debug)]
10pub struct ApiControllerAddRoleParams {
11    /// The details of the role
12    pub body: models::Role
13}
14
15/// struct for passing parameters to the method [`delete_role`]
16#[derive(Clone, Debug)]
17pub struct ApiControllerDeleteRoleParams {
18    /// The details of the role
19    pub body: models::Role
20}
21
22/// struct for passing parameters to the method [`get_role`]
23#[derive(Clone, Debug)]
24pub struct ApiControllerGetRoleParams {
25    /// The id ( owner/name ) of the role
26    pub id: String
27}
28
29/// struct for passing parameters to the method [`get_roles`]
30#[derive(Clone, Debug)]
31pub struct ApiControllerGetRolesParams {
32    /// The owner of roles
33    pub owner: String
34}
35
36/// struct for passing parameters to the method [`update_role`]
37#[derive(Clone, Debug)]
38pub struct ApiControllerUpdateRoleParams {
39    /// The id ( owner/name ) of the role
40    pub id: String,
41    /// The details of the role
42    pub body: models::Role
43}
44
45
46/// struct for typed errors of method [`add_role`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ApiControllerAddRoleError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`delete_role`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum ApiControllerDeleteRoleError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_role`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ApiControllerGetRoleError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`get_roles`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ApiControllerGetRolesError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`update_role`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ApiControllerUpdateRoleError {
78    UnknownValue(serde_json::Value),
79}
80
81
82/// add role
83pub async fn add_role(configuration: &configuration::Configuration, params: ApiControllerAddRoleParams) -> Result<models::ControllersResponse, Error<ApiControllerAddRoleError>> {
84    let local_var_configuration = configuration;
85
86    // unbox the parameters
87    let body = params.body;
88
89
90    let local_var_client = &local_var_configuration.client;
91
92    let local_var_uri_str = format!("{}/api/add-role", local_var_configuration.base_path);
93    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
94
95    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
96        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
97    }
98    local_var_req_builder = local_var_req_builder.json(&body);
99
100    let local_var_req = local_var_req_builder.build()?;
101    let local_var_resp = local_var_client.execute(local_var_req).await?;
102
103    let local_var_status = local_var_resp.status();
104    let local_var_content = local_var_resp.text().await?;
105
106    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107        serde_json::from_str(&local_var_content).map_err(Error::from)
108    } else {
109        let local_var_entity: Option<ApiControllerAddRoleError> = serde_json::from_str(&local_var_content).ok();
110        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111        Err(Error::ResponseError(local_var_error))
112    }
113}
114
115/// delete role
116pub async fn delete_role(configuration: &configuration::Configuration, params: ApiControllerDeleteRoleParams) -> Result<models::ControllersResponse, Error<ApiControllerDeleteRoleError>> {
117    let local_var_configuration = configuration;
118
119    // unbox the parameters
120    let body = params.body;
121
122
123    let local_var_client = &local_var_configuration.client;
124
125    let local_var_uri_str = format!("{}/api/delete-role", local_var_configuration.base_path);
126    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
127
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130    }
131    local_var_req_builder = local_var_req_builder.json(&body);
132
133    let local_var_req = local_var_req_builder.build()?;
134    let local_var_resp = local_var_client.execute(local_var_req).await?;
135
136    let local_var_status = local_var_resp.status();
137    let local_var_content = local_var_resp.text().await?;
138
139    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
140        serde_json::from_str(&local_var_content).map_err(Error::from)
141    } else {
142        let local_var_entity: Option<ApiControllerDeleteRoleError> = serde_json::from_str(&local_var_content).ok();
143        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
144        Err(Error::ResponseError(local_var_error))
145    }
146}
147
148/// get role
149pub async fn get_role(configuration: &configuration::Configuration, params: ApiControllerGetRoleParams) -> Result<models::Role, Error<ApiControllerGetRoleError>> {
150    let local_var_configuration = configuration;
151
152    // unbox the parameters
153    let id = params.id;
154
155
156    let local_var_client = &local_var_configuration.client;
157
158    let local_var_uri_str = format!("{}/api/get-role", local_var_configuration.base_path);
159    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
160
161    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
162    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
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        serde_json::from_str(&local_var_content).map_err(Error::from)
174    } else {
175        let local_var_entity: Option<ApiControllerGetRoleError> = 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
181/// get roles
182pub async fn get_roles(configuration: &configuration::Configuration, params: ApiControllerGetRolesParams) -> Result<Vec<models::Role>, Error<ApiControllerGetRolesError>> {
183    let local_var_configuration = configuration;
184
185    // unbox the parameters
186    let owner = params.owner;
187
188
189    let local_var_client = &local_var_configuration.client;
190
191    let local_var_uri_str = format!("{}/api/get-roles", local_var_configuration.base_path);
192    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
193
194    local_var_req_builder = local_var_req_builder.query(&[("owner", &owner.to_string())]);
195    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
196        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
197    }
198
199    let local_var_req = local_var_req_builder.build()?;
200    let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202    let local_var_status = local_var_resp.status();
203    let local_var_content = local_var_resp.text().await?;
204
205    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206        serde_json::from_str(&local_var_content).map_err(Error::from)
207    } else {
208        let local_var_entity: Option<ApiControllerGetRolesError> = serde_json::from_str(&local_var_content).ok();
209        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
210        Err(Error::ResponseError(local_var_error))
211    }
212}
213
214/// update role
215pub async fn update_role(configuration: &configuration::Configuration, params: ApiControllerUpdateRoleParams) -> Result<models::ControllersResponse, Error<ApiControllerUpdateRoleError>> {
216    let local_var_configuration = configuration;
217
218    // unbox the parameters
219    let id = params.id;
220    let body = params.body;
221
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/api/update-role", local_var_configuration.base_path);
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
227
228    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
229    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231    }
232    local_var_req_builder = local_var_req_builder.json(&body);
233
234    let local_var_req = local_var_req_builder.build()?;
235    let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237    let local_var_status = local_var_resp.status();
238    let local_var_content = local_var_resp.text().await?;
239
240    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
241        serde_json::from_str(&local_var_content).map_err(Error::from)
242    } else {
243        let local_var_entity: Option<ApiControllerUpdateRoleError> = serde_json::from_str(&local_var_content).ok();
244        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
245        Err(Error::ResponseError(local_var_error))
246    }
247}
248