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