casdoor_sdk/apis/
session_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_session`]
9#[derive(Clone, Debug)]
10pub struct ApiControllerAddSessionParams {
11    /// The id(organization/application/user) of session
12    pub id: String,
13    /// sessionId to be added
14    pub session_id: String
15}
16
17/// struct for passing parameters to the method [`delete_session`]
18#[derive(Clone, Debug)]
19pub struct ApiControllerDeleteSessionParams {
20    /// The id(organization/application/user) of session
21    pub id: String
22}
23
24/// struct for passing parameters to the method [`get_sessions`]
25#[derive(Clone, Debug)]
26pub struct ApiControllerGetSessionsParams {
27    /// The organization name
28    pub owner: String
29}
30
31/// struct for passing parameters to the method [`get_single_session`]
32#[derive(Clone, Debug)]
33pub struct ApiControllerGetSingleSessionParams {
34    /// The id(organization/application/user) of session
35    pub id: String
36}
37
38/// struct for passing parameters to the method [`is_session_duplicated`]
39#[derive(Clone, Debug)]
40pub struct ApiControllerIsSessionDuplicatedParams {
41    /// The id(organization/application/user) of session
42    pub id: String,
43    /// sessionId to be checked
44    pub session_id: String
45}
46
47/// struct for passing parameters to the method [`update_session`]
48#[derive(Clone, Debug)]
49pub struct ApiControllerUpdateSessionParams {
50    /// The id(organization/application/user) of session
51    pub id: String
52}
53
54
55/// struct for typed errors of method [`add_session`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum ApiControllerAddSessionError {
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`delete_session`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum ApiControllerDeleteSessionError {
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`get_sessions`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ApiControllerGetSessionsError {
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`get_single_session`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ApiControllerGetSingleSessionError {
80    UnknownValue(serde_json::Value),
81}
82
83/// struct for typed errors of method [`is_session_duplicated`]
84#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum ApiControllerIsSessionDuplicatedError {
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`update_session`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum ApiControllerUpdateSessionError {
94    UnknownValue(serde_json::Value),
95}
96
97
98/// Add session for one user in one application. If there are other existing sessions, join the session into the list.
99pub async fn add_session(configuration: &configuration::Configuration, params: ApiControllerAddSessionParams) -> Result<Vec<String>, Error<ApiControllerAddSessionError>> {
100    let local_var_configuration = configuration;
101
102    // unbox the parameters
103    let id = params.id;
104    let session_id = params.session_id;
105
106
107    let local_var_client = &local_var_configuration.client;
108
109    let local_var_uri_str = format!("{}/api/add-session", local_var_configuration.base_path);
110    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
111
112    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
113    local_var_req_builder = local_var_req_builder.query(&[("sessionId", &session_id.to_string())]);
114    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
116    }
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    let local_var_status = local_var_resp.status();
122    let local_var_content = local_var_resp.text().await?;
123
124    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125        serde_json::from_str(&local_var_content).map_err(Error::from)
126    } else {
127        let local_var_entity: Option<ApiControllerAddSessionError> = serde_json::from_str(&local_var_content).ok();
128        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
129        Err(Error::ResponseError(local_var_error))
130    }
131}
132
133/// Delete session for one user in one application.
134pub async fn delete_session(configuration: &configuration::Configuration, params: ApiControllerDeleteSessionParams) -> Result<Vec<String>, Error<ApiControllerDeleteSessionError>> {
135    let local_var_configuration = configuration;
136
137    // unbox the parameters
138    let id = params.id;
139
140
141    let local_var_client = &local_var_configuration.client;
142
143    let local_var_uri_str = format!("{}/api/delete-session", local_var_configuration.base_path);
144    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
145
146    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
147    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149    }
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        serde_json::from_str(&local_var_content).map_err(Error::from)
159    } else {
160        let local_var_entity: Option<ApiControllerDeleteSessionError> = serde_json::from_str(&local_var_content).ok();
161        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
162        Err(Error::ResponseError(local_var_error))
163    }
164}
165
166/// Get organization user sessions.
167pub async fn get_sessions(configuration: &configuration::Configuration, params: ApiControllerGetSessionsParams) -> Result<Vec<String>, Error<ApiControllerGetSessionsError>> {
168    let local_var_configuration = configuration;
169
170    // unbox the parameters
171    let owner = params.owner;
172
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!("{}/api/get-sessions", local_var_configuration.base_path);
177    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
178
179    local_var_req_builder = local_var_req_builder.query(&[("owner", &owner.to_string())]);
180    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
181        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
182    }
183
184    let local_var_req = local_var_req_builder.build()?;
185    let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187    let local_var_status = local_var_resp.status();
188    let local_var_content = local_var_resp.text().await?;
189
190    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191        serde_json::from_str(&local_var_content).map_err(Error::from)
192    } else {
193        let local_var_entity: Option<ApiControllerGetSessionsError> = serde_json::from_str(&local_var_content).ok();
194        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
195        Err(Error::ResponseError(local_var_error))
196    }
197}
198
199/// Get session for one user in one application.
200pub async fn get_single_session(configuration: &configuration::Configuration, params: ApiControllerGetSingleSessionParams) -> Result<Vec<String>, Error<ApiControllerGetSingleSessionError>> {
201    let local_var_configuration = configuration;
202
203    // unbox the parameters
204    let id = params.id;
205
206
207    let local_var_client = &local_var_configuration.client;
208
209    let local_var_uri_str = format!("{}/api/get-session", local_var_configuration.base_path);
210    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
211
212    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
213    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
214        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215    }
216
217    let local_var_req = local_var_req_builder.build()?;
218    let local_var_resp = local_var_client.execute(local_var_req).await?;
219
220    let local_var_status = local_var_resp.status();
221    let local_var_content = local_var_resp.text().await?;
222
223    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
224        serde_json::from_str(&local_var_content).map_err(Error::from)
225    } else {
226        let local_var_entity: Option<ApiControllerGetSingleSessionError> = serde_json::from_str(&local_var_content).ok();
227        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
228        Err(Error::ResponseError(local_var_error))
229    }
230}
231
232/// Check if there are other different sessions for one user in one application.
233pub async fn is_session_duplicated(configuration: &configuration::Configuration, params: ApiControllerIsSessionDuplicatedParams) -> Result<Vec<String>, Error<ApiControllerIsSessionDuplicatedError>> {
234    let local_var_configuration = configuration;
235
236    // unbox the parameters
237    let id = params.id;
238    let session_id = params.session_id;
239
240
241    let local_var_client = &local_var_configuration.client;
242
243    let local_var_uri_str = format!("{}/api/is-session-duplicated", local_var_configuration.base_path);
244    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
245
246    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
247    local_var_req_builder = local_var_req_builder.query(&[("sessionId", &session_id.to_string())]);
248    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
249        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
250    }
251
252    let local_var_req = local_var_req_builder.build()?;
253    let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255    let local_var_status = local_var_resp.status();
256    let local_var_content = local_var_resp.text().await?;
257
258    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259        serde_json::from_str(&local_var_content).map_err(Error::from)
260    } else {
261        let local_var_entity: Option<ApiControllerIsSessionDuplicatedError> = serde_json::from_str(&local_var_content).ok();
262        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263        Err(Error::ResponseError(local_var_error))
264    }
265}
266
267/// Update session for one user in one application.
268pub async fn update_session(configuration: &configuration::Configuration, params: ApiControllerUpdateSessionParams) -> Result<Vec<String>, Error<ApiControllerUpdateSessionError>> {
269    let local_var_configuration = configuration;
270
271    // unbox the parameters
272    let id = params.id;
273
274
275    let local_var_client = &local_var_configuration.client;
276
277    let local_var_uri_str = format!("{}/api/update-session", local_var_configuration.base_path);
278    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
279
280    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
281    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
282        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283    }
284
285    let local_var_req = local_var_req_builder.build()?;
286    let local_var_resp = local_var_client.execute(local_var_req).await?;
287
288    let local_var_status = local_var_resp.status();
289    let local_var_content = local_var_resp.text().await?;
290
291    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
292        serde_json::from_str(&local_var_content).map_err(Error::from)
293    } else {
294        let local_var_entity: Option<ApiControllerUpdateSessionError> = serde_json::from_str(&local_var_content).ok();
295        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
296        Err(Error::ResponseError(local_var_error))
297    }
298}
299