Skip to main content

geoengine_api_client/apis/
session_api.rs

1/*
2 * Geo Engine API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * Contact: dev@geoengine.de
7 * Generated by: https://openapi-generator.tech
8 */
9
10
11use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13use crate::{apis::ResponseContent, models};
14use super::{Error, configuration, ContentType};
15
16
17/// struct for typed errors of method [`anonymous_handler`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AnonymousHandlerError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`login_handler`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum LoginHandlerError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`logout_handler`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum LogoutHandlerError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`oidc_init`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum OidcInitError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`oidc_login`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum OidcLoginError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`register_user_handler`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum RegisterUserHandlerError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`session_handler`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum SessionHandlerError {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`session_project_handler`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum SessionProjectHandlerError {
70    UnknownValue(serde_json::Value),
71}
72
73/// struct for typed errors of method [`session_view_handler`]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum SessionViewHandlerError {
77    UnknownValue(serde_json::Value),
78}
79
80
81pub async fn anonymous_handler(configuration: &configuration::Configuration, ) -> Result<models::UserSession, Error<AnonymousHandlerError>> {
82
83    let uri_str = format!("{}/anonymous", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
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
90    let req = req_builder.build()?;
91    let resp = configuration.client.execute(req).await?;
92
93    let status = resp.status();
94    let content_type = resp
95        .headers()
96        .get("content-type")
97        .and_then(|v| v.to_str().ok())
98        .unwrap_or("application/octet-stream");
99    let content_type = super::ContentType::from(content_type);
100
101    if !status.is_client_error() && !status.is_server_error() {
102        let content = resp.text().await?;
103        match content_type {
104            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
105            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSession`"))),
106            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSession`")))),
107        }
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<AnonymousHandlerError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent { status, content, entity }))
112    }
113}
114
115pub async fn login_handler(configuration: &configuration::Configuration, user_credentials: models::UserCredentials) -> Result<models::UserSession, Error<LoginHandlerError>> {
116    // add a prefix to parameters to efficiently prevent name collisions
117    let p_body_user_credentials = user_credentials;
118
119    let uri_str = format!("{}/login", configuration.base_path);
120    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
121
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125    req_builder = req_builder.json(&p_body_user_credentials);
126
127    let req = req_builder.build()?;
128    let resp = configuration.client.execute(req).await?;
129
130    let status = resp.status();
131    let content_type = resp
132        .headers()
133        .get("content-type")
134        .and_then(|v| v.to_str().ok())
135        .unwrap_or("application/octet-stream");
136    let content_type = super::ContentType::from(content_type);
137
138    if !status.is_client_error() && !status.is_server_error() {
139        let content = resp.text().await?;
140        match content_type {
141            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
142            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSession`"))),
143            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSession`")))),
144        }
145    } else {
146        let content = resp.text().await?;
147        let entity: Option<LoginHandlerError> = serde_json::from_str(&content).ok();
148        Err(Error::ResponseError(ResponseContent { status, content, entity }))
149    }
150}
151
152pub async fn logout_handler(configuration: &configuration::Configuration, ) -> Result<(), Error<LogoutHandlerError>> {
153
154    let uri_str = format!("{}/logout", configuration.base_path);
155    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
156
157    if let Some(ref user_agent) = configuration.user_agent {
158        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
159    }
160    if let Some(ref token) = configuration.bearer_access_token {
161        req_builder = req_builder.bearer_auth(token.to_owned());
162    };
163
164    let req = req_builder.build()?;
165    let resp = configuration.client.execute(req).await?;
166
167    let status = resp.status();
168
169    if !status.is_client_error() && !status.is_server_error() {
170        Ok(())
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<LogoutHandlerError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent { status, content, entity }))
175    }
176}
177
178/// # Errors  This call fails if Open ID Connect is disabled, misconfigured or the Id Provider is unreachable.  
179pub async fn oidc_init(configuration: &configuration::Configuration, redirect_uri: &str) -> Result<models::AuthCodeRequestUrl, Error<OidcInitError>> {
180    // add a prefix to parameters to efficiently prevent name collisions
181    let p_query_redirect_uri = redirect_uri;
182
183    let uri_str = format!("{}/oidcInit", configuration.base_path);
184    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
185
186    req_builder = req_builder.query(&[("redirectUri", &p_query_redirect_uri.to_string())]);
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190
191    let req = req_builder.build()?;
192    let resp = configuration.client.execute(req).await?;
193
194    let status = resp.status();
195    let content_type = resp
196        .headers()
197        .get("content-type")
198        .and_then(|v| v.to_str().ok())
199        .unwrap_or("application/octet-stream");
200    let content_type = super::ContentType::from(content_type);
201
202    if !status.is_client_error() && !status.is_server_error() {
203        let content = resp.text().await?;
204        match content_type {
205            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
206            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AuthCodeRequestUrl`"))),
207            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AuthCodeRequestUrl`")))),
208        }
209    } else {
210        let content = resp.text().await?;
211        let entity: Option<OidcInitError> = serde_json::from_str(&content).ok();
212        Err(Error::ResponseError(ResponseContent { status, content, entity }))
213    }
214}
215
216/// # Errors  This call fails if the [`AuthCodeResponse`] is invalid, if a previous oidcLogin call with the same state was already successfully or unsuccessfully resolved, if the Open Id Connect configuration is invalid, or if the Id Provider is unreachable.  
217pub async fn oidc_login(configuration: &configuration::Configuration, redirect_uri: &str, auth_code_response: models::AuthCodeResponse) -> Result<models::UserSession, Error<OidcLoginError>> {
218    // add a prefix to parameters to efficiently prevent name collisions
219    let p_query_redirect_uri = redirect_uri;
220    let p_body_auth_code_response = auth_code_response;
221
222    let uri_str = format!("{}/oidcLogin", configuration.base_path);
223    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
224
225    req_builder = req_builder.query(&[("redirectUri", &p_query_redirect_uri.to_string())]);
226    if let Some(ref user_agent) = configuration.user_agent {
227        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228    }
229    req_builder = req_builder.json(&p_body_auth_code_response);
230
231    let req = req_builder.build()?;
232    let resp = configuration.client.execute(req).await?;
233
234    let status = resp.status();
235    let content_type = resp
236        .headers()
237        .get("content-type")
238        .and_then(|v| v.to_str().ok())
239        .unwrap_or("application/octet-stream");
240    let content_type = super::ContentType::from(content_type);
241
242    if !status.is_client_error() && !status.is_server_error() {
243        let content = resp.text().await?;
244        match content_type {
245            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
246            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSession`"))),
247            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSession`")))),
248        }
249    } else {
250        let content = resp.text().await?;
251        let entity: Option<OidcLoginError> = serde_json::from_str(&content).ok();
252        Err(Error::ResponseError(ResponseContent { status, content, entity }))
253    }
254}
255
256pub async fn register_user_handler(configuration: &configuration::Configuration, user_registration: models::UserRegistration) -> Result<uuid::Uuid, Error<RegisterUserHandlerError>> {
257    // add a prefix to parameters to efficiently prevent name collisions
258    let p_body_user_registration = user_registration;
259
260    let uri_str = format!("{}/user", configuration.base_path);
261    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
262
263    if let Some(ref user_agent) = configuration.user_agent {
264        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265    }
266    req_builder = req_builder.json(&p_body_user_registration);
267
268    let req = req_builder.build()?;
269    let resp = configuration.client.execute(req).await?;
270
271    let status = resp.status();
272    let content_type = resp
273        .headers()
274        .get("content-type")
275        .and_then(|v| v.to_str().ok())
276        .unwrap_or("application/octet-stream");
277    let content_type = super::ContentType::from(content_type);
278
279    if !status.is_client_error() && !status.is_server_error() {
280        let content = resp.text().await?;
281        match content_type {
282            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
283            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `uuid::Uuid`"))),
284            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `uuid::Uuid`")))),
285        }
286    } else {
287        let content = resp.text().await?;
288        let entity: Option<RegisterUserHandlerError> = serde_json::from_str(&content).ok();
289        Err(Error::ResponseError(ResponseContent { status, content, entity }))
290    }
291}
292
293pub async fn session_handler(configuration: &configuration::Configuration, ) -> Result<models::UserSession, Error<SessionHandlerError>> {
294
295    let uri_str = format!("{}/session", configuration.base_path);
296    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
297
298    if let Some(ref user_agent) = configuration.user_agent {
299        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
300    }
301    if let Some(ref token) = configuration.bearer_access_token {
302        req_builder = req_builder.bearer_auth(token.to_owned());
303    };
304
305    let req = req_builder.build()?;
306    let resp = configuration.client.execute(req).await?;
307
308    let status = resp.status();
309    let content_type = resp
310        .headers()
311        .get("content-type")
312        .and_then(|v| v.to_str().ok())
313        .unwrap_or("application/octet-stream");
314    let content_type = super::ContentType::from(content_type);
315
316    if !status.is_client_error() && !status.is_server_error() {
317        let content = resp.text().await?;
318        match content_type {
319            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
320            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserSession`"))),
321            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UserSession`")))),
322        }
323    } else {
324        let content = resp.text().await?;
325        let entity: Option<SessionHandlerError> = serde_json::from_str(&content).ok();
326        Err(Error::ResponseError(ResponseContent { status, content, entity }))
327    }
328}
329
330pub async fn session_project_handler(configuration: &configuration::Configuration, project: &str) -> Result<(), Error<SessionProjectHandlerError>> {
331    // add a prefix to parameters to efficiently prevent name collisions
332    let p_path_project = project;
333
334    let uri_str = format!("{}/session/project/{project}", configuration.base_path, project=crate::apis::urlencode(p_path_project));
335    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
336
337    if let Some(ref user_agent) = configuration.user_agent {
338        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
339    }
340    if let Some(ref token) = configuration.bearer_access_token {
341        req_builder = req_builder.bearer_auth(token.to_owned());
342    };
343
344    let req = req_builder.build()?;
345    let resp = configuration.client.execute(req).await?;
346
347    let status = resp.status();
348
349    if !status.is_client_error() && !status.is_server_error() {
350        Ok(())
351    } else {
352        let content = resp.text().await?;
353        let entity: Option<SessionProjectHandlerError> = serde_json::from_str(&content).ok();
354        Err(Error::ResponseError(ResponseContent { status, content, entity }))
355    }
356}
357
358pub async fn session_view_handler(configuration: &configuration::Configuration, st_rectangle: models::StRectangle) -> Result<(), Error<SessionViewHandlerError>> {
359    // add a prefix to parameters to efficiently prevent name collisions
360    let p_body_st_rectangle = st_rectangle;
361
362    let uri_str = format!("{}/session/view", configuration.base_path);
363    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
364
365    if let Some(ref user_agent) = configuration.user_agent {
366        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
367    }
368    if let Some(ref token) = configuration.bearer_access_token {
369        req_builder = req_builder.bearer_auth(token.to_owned());
370    };
371    req_builder = req_builder.json(&p_body_st_rectangle);
372
373    let req = req_builder.build()?;
374    let resp = configuration.client.execute(req).await?;
375
376    let status = resp.status();
377
378    if !status.is_client_error() && !status.is_server_error() {
379        Ok(())
380    } else {
381        let content = resp.text().await?;
382        let entity: Option<SessionViewHandlerError> = serde_json::from_str(&content).ok();
383        Err(Error::ResponseError(ResponseContent { status, content, entity }))
384    }
385}
386