p7m_userauth/apis/
account_api.rs

1/*
2 * User and Authentication Backend
3 *
4 * # API for authentication and managing user accounts  This is the API of the service at P7M that manages tenants, accounts and authentication. It is the basis of many services of P7M.  The caller has to be authenticated with the system and provide a JWT token in the Authorization header of the HTTP request. When using the API you typically get this token by authenticating first with OAuth 2.0.  When you are trying this API using the Swagger interface, you need to click the `Authorize` button and then again the Authorize button in the pop-up that gets opened.
5 *
6 * The version of the OpenAPI document: 0.14.2
7 * Contact: tech@p7m.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 [`delete_account_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteAccountByIdError {
22    Status400(),
23    Status403(),
24    Status404(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_account_by_id`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetAccountByIdError {
32    Status403(),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_accounts`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetAccountsError {
40    Status403(),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`post_accounts`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum PostAccountsError {
48    Status403(),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`put_account_by_id`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum PutAccountByIdError {
56    Status400(),
57    Status403(),
58    Status404(),
59    UnknownValue(serde_json::Value),
60}
61
62
63pub async fn delete_account_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteAccountByIdError>> {
64    // add a prefix to parameters to efficiently prevent name collisions
65    let p_id = id;
66
67    let uri_str = format!("{}/accounts/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
68    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
69
70    if let Some(ref user_agent) = configuration.user_agent {
71        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
72    }
73    if let Some(ref token) = configuration.oauth_access_token {
74        req_builder = req_builder.bearer_auth(token.to_owned());
75    };
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81
82    if !status.is_client_error() && !status.is_server_error() {
83        Ok(())
84    } else {
85        let content = resp.text().await?;
86        let entity: Option<DeleteAccountByIdError> = serde_json::from_str(&content).ok();
87        Err(Error::ResponseError(ResponseContent { status, content, entity }))
88    }
89}
90
91pub async fn get_account_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Account, Error<GetAccountByIdError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_id = id;
94
95    let uri_str = format!("{}/accounts/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
96    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
97
98    if let Some(ref user_agent) = configuration.user_agent {
99        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100    }
101    if let Some(ref token) = configuration.oauth_access_token {
102        req_builder = req_builder.bearer_auth(token.to_owned());
103    };
104
105    let req = req_builder.build()?;
106    let resp = configuration.client.execute(req).await?;
107
108    let status = resp.status();
109    let content_type = resp
110        .headers()
111        .get("content-type")
112        .and_then(|v| v.to_str().ok())
113        .unwrap_or("application/octet-stream");
114    let content_type = super::ContentType::from(content_type);
115
116    if !status.is_client_error() && !status.is_server_error() {
117        let content = resp.text().await?;
118        match content_type {
119            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Account`"))),
121            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::Account`")))),
122        }
123    } else {
124        let content = resp.text().await?;
125        let entity: Option<GetAccountByIdError> = serde_json::from_str(&content).ok();
126        Err(Error::ResponseError(ResponseContent { status, content, entity }))
127    }
128}
129
130/// An account represents an authentication identity
131pub async fn get_accounts(configuration: &configuration::Configuration, changed_since: Option<String>) -> Result<models::ListWrapperAccount, Error<GetAccountsError>> {
132    // add a prefix to parameters to efficiently prevent name collisions
133    let p_changed_since = changed_since;
134
135    let uri_str = format!("{}/accounts", configuration.base_path);
136    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
137
138    if let Some(ref param_value) = p_changed_since {
139        req_builder = req_builder.query(&[("changed_since", &param_value.to_string())]);
140    }
141    if let Some(ref user_agent) = configuration.user_agent {
142        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143    }
144    if let Some(ref token) = configuration.oauth_access_token {
145        req_builder = req_builder.bearer_auth(token.to_owned());
146    };
147
148    let req = req_builder.build()?;
149    let resp = configuration.client.execute(req).await?;
150
151    let status = resp.status();
152    let content_type = resp
153        .headers()
154        .get("content-type")
155        .and_then(|v| v.to_str().ok())
156        .unwrap_or("application/octet-stream");
157    let content_type = super::ContentType::from(content_type);
158
159    if !status.is_client_error() && !status.is_server_error() {
160        let content = resp.text().await?;
161        match content_type {
162            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperAccount`"))),
164            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::ListWrapperAccount`")))),
165        }
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<GetAccountsError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173pub async fn post_accounts(configuration: &configuration::Configuration, new_account: models::NewAccount) -> Result<models::Account, Error<PostAccountsError>> {
174    // add a prefix to parameters to efficiently prevent name collisions
175    let p_new_account = new_account;
176
177    let uri_str = format!("{}/accounts", configuration.base_path);
178    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
179
180    if let Some(ref user_agent) = configuration.user_agent {
181        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182    }
183    if let Some(ref token) = configuration.oauth_access_token {
184        req_builder = req_builder.bearer_auth(token.to_owned());
185    };
186    req_builder = req_builder.json(&p_new_account);
187
188    let req = req_builder.build()?;
189    let resp = configuration.client.execute(req).await?;
190
191    let status = resp.status();
192    let content_type = resp
193        .headers()
194        .get("content-type")
195        .and_then(|v| v.to_str().ok())
196        .unwrap_or("application/octet-stream");
197    let content_type = super::ContentType::from(content_type);
198
199    if !status.is_client_error() && !status.is_server_error() {
200        let content = resp.text().await?;
201        match content_type {
202            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
203            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Account`"))),
204            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::Account`")))),
205        }
206    } else {
207        let content = resp.text().await?;
208        let entity: Option<PostAccountsError> = serde_json::from_str(&content).ok();
209        Err(Error::ResponseError(ResponseContent { status, content, entity }))
210    }
211}
212
213pub async fn put_account_by_id(configuration: &configuration::Configuration, id: &str, new_account: models::NewAccount) -> Result<models::Account, Error<PutAccountByIdError>> {
214    // add a prefix to parameters to efficiently prevent name collisions
215    let p_id = id;
216    let p_new_account = new_account;
217
218    let uri_str = format!("{}/accounts/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
219    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
220
221    if let Some(ref user_agent) = configuration.user_agent {
222        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
223    }
224    if let Some(ref token) = configuration.oauth_access_token {
225        req_builder = req_builder.bearer_auth(token.to_owned());
226    };
227    req_builder = req_builder.json(&p_new_account);
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Account`"))),
245            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::Account`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<PutAccountByIdError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
251    }
252}
253