p7m_userauth/apis/
tenant_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_tenant_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteTenantByIdError {
22    Status400(),
23    Status403(),
24    Status404(),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_tenant_by_id`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetTenantByIdError {
32    Status401(),
33    Status403(),
34    Status404(),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_tenants`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetTenantsError {
42    Status401(),
43    Status403(),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`post_tenants`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum PostTenantsError {
51    Status401(),
52    Status403(),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`put_tenant_by_id`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum PutTenantByIdError {
60    Status400(),
61    Status403(),
62    Status404(),
63    UnknownValue(serde_json::Value),
64}
65
66
67pub async fn delete_tenant_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteTenantByIdError>> {
68    // add a prefix to parameters to efficiently prevent name collisions
69    let p_id = id;
70
71    let uri_str = format!("{}/tenants/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
72    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
73
74    if let Some(ref user_agent) = configuration.user_agent {
75        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76    }
77    if let Some(ref token) = configuration.oauth_access_token {
78        req_builder = req_builder.bearer_auth(token.to_owned());
79    };
80
81    let req = req_builder.build()?;
82    let resp = configuration.client.execute(req).await?;
83
84    let status = resp.status();
85
86    if !status.is_client_error() && !status.is_server_error() {
87        Ok(())
88    } else {
89        let content = resp.text().await?;
90        let entity: Option<DeleteTenantByIdError> = serde_json::from_str(&content).ok();
91        Err(Error::ResponseError(ResponseContent { status, content, entity }))
92    }
93}
94
95pub async fn get_tenant_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Tenant, Error<GetTenantByIdError>> {
96    // add a prefix to parameters to efficiently prevent name collisions
97    let p_id = id;
98
99    let uri_str = format!("{}/tenants/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
100    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
101
102    if let Some(ref user_agent) = configuration.user_agent {
103        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104    }
105    if let Some(ref token) = configuration.oauth_access_token {
106        req_builder = req_builder.bearer_auth(token.to_owned());
107    };
108
109    let req = req_builder.build()?;
110    let resp = configuration.client.execute(req).await?;
111
112    let status = resp.status();
113    let content_type = resp
114        .headers()
115        .get("content-type")
116        .and_then(|v| v.to_str().ok())
117        .unwrap_or("application/octet-stream");
118    let content_type = super::ContentType::from(content_type);
119
120    if !status.is_client_error() && !status.is_server_error() {
121        let content = resp.text().await?;
122        match content_type {
123            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
124            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Tenant`"))),
125            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::Tenant`")))),
126        }
127    } else {
128        let content = resp.text().await?;
129        let entity: Option<GetTenantByIdError> = serde_json::from_str(&content).ok();
130        Err(Error::ResponseError(ResponseContent { status, content, entity }))
131    }
132}
133
134/// A tenant is typically a company or surgery that uses services of P7M.  Data within the services of P7M arescoped and isolated between tenants. A tenant represents the boundaries between the data of different clients. Data within P7M is stored tagged with the tenant_id to identify the owning tenant of the datum.
135pub async fn get_tenants(configuration: &configuration::Configuration, ) -> Result<models::ListWrapperTenant, Error<GetTenantsError>> {
136
137    let uri_str = format!("{}/tenants", configuration.base_path);
138    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(ref token) = configuration.oauth_access_token {
144        req_builder = req_builder.bearer_auth(token.to_owned());
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151    let content_type = resp
152        .headers()
153        .get("content-type")
154        .and_then(|v| v.to_str().ok())
155        .unwrap_or("application/octet-stream");
156    let content_type = super::ContentType::from(content_type);
157
158    if !status.is_client_error() && !status.is_server_error() {
159        let content = resp.text().await?;
160        match content_type {
161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperTenant`"))),
163            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::ListWrapperTenant`")))),
164        }
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<GetTenantsError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172pub async fn post_tenants(configuration: &configuration::Configuration, new_tenant: models::NewTenant) -> Result<models::Tenant, Error<PostTenantsError>> {
173    // add a prefix to parameters to efficiently prevent name collisions
174    let p_new_tenant = new_tenant;
175
176    let uri_str = format!("{}/tenants", configuration.base_path);
177    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
178
179    if let Some(ref user_agent) = configuration.user_agent {
180        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181    }
182    if let Some(ref token) = configuration.oauth_access_token {
183        req_builder = req_builder.bearer_auth(token.to_owned());
184    };
185    req_builder = req_builder.json(&p_new_tenant);
186
187    let req = req_builder.build()?;
188    let resp = configuration.client.execute(req).await?;
189
190    let status = resp.status();
191    let content_type = resp
192        .headers()
193        .get("content-type")
194        .and_then(|v| v.to_str().ok())
195        .unwrap_or("application/octet-stream");
196    let content_type = super::ContentType::from(content_type);
197
198    if !status.is_client_error() && !status.is_server_error() {
199        let content = resp.text().await?;
200        match content_type {
201            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
202            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Tenant`"))),
203            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::Tenant`")))),
204        }
205    } else {
206        let content = resp.text().await?;
207        let entity: Option<PostTenantsError> = serde_json::from_str(&content).ok();
208        Err(Error::ResponseError(ResponseContent { status, content, entity }))
209    }
210}
211
212pub async fn put_tenant_by_id(configuration: &configuration::Configuration, id: &str, new_tenant: models::NewTenant) -> Result<models::Tenant, Error<PutTenantByIdError>> {
213    // add a prefix to parameters to efficiently prevent name collisions
214    let p_id = id;
215    let p_new_tenant = new_tenant;
216
217    let uri_str = format!("{}/tenants/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
218    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
219
220    if let Some(ref user_agent) = configuration.user_agent {
221        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222    }
223    if let Some(ref token) = configuration.oauth_access_token {
224        req_builder = req_builder.bearer_auth(token.to_owned());
225    };
226    req_builder = req_builder.json(&p_new_tenant);
227
228    let req = req_builder.build()?;
229    let resp = configuration.client.execute(req).await?;
230
231    let status = resp.status();
232    let content_type = resp
233        .headers()
234        .get("content-type")
235        .and_then(|v| v.to_str().ok())
236        .unwrap_or("application/octet-stream");
237    let content_type = super::ContentType::from(content_type);
238
239    if !status.is_client_error() && !status.is_server_error() {
240        let content = resp.text().await?;
241        match content_type {
242            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
243            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Tenant`"))),
244            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::Tenant`")))),
245        }
246    } else {
247        let content = resp.text().await?;
248        let entity: Option<PutTenantByIdError> = serde_json::from_str(&content).ok();
249        Err(Error::ResponseError(ResponseContent { status, content, entity }))
250    }
251}
252