1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddUserError {
22 Status400(models::ValidationErrorResponse),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteUserByIdError {
30 Status400(models::ValidationErrorResponse),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAuthenticationActivityError {
38 Status400(models::ValidationErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetLatestAuthenticationActivityByUserIdError {
46 Status400(models::ValidationErrorResponse),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetUsersError {
54 Status400(models::ValidationErrorResponse),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum UpdatePasswordByUserIdError {
62 Status400(models::ValidationErrorResponse),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum UpdateUserByIdError {
70 Status400(models::ValidationErrorResponse),
71 UnknownValue(serde_json::Value),
72}
73
74
75pub async fn add_user(configuration: &configuration::Configuration, user_creation_dto: models::UserCreationDto) -> Result<models::UserDto, Error<AddUserError>> {
77 let p_body_user_creation_dto = user_creation_dto;
79
80 let uri_str = format!("{}/api/v2/users", configuration.base_path);
81 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
82
83 if let Some(ref user_agent) = configuration.user_agent {
84 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
85 }
86 if let Some(ref apikey) = configuration.api_key {
87 let key = apikey.key.clone();
88 let value = match apikey.prefix {
89 Some(ref prefix) => format!("{} {}", prefix, key),
90 None => key,
91 };
92 req_builder = req_builder.header("X-API-Key", value);
93 };
94 if let Some(ref auth_conf) = configuration.basic_auth {
95 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
96 };
97 req_builder = req_builder.json(&p_body_user_creation_dto);
98
99 let req = req_builder.build()?;
100 let resp = configuration.client.execute(req).await?;
101
102 let status = resp.status();
103 let content_type = resp
104 .headers()
105 .get("content-type")
106 .and_then(|v| v.to_str().ok())
107 .unwrap_or("application/octet-stream");
108 let content_type = super::ContentType::from(content_type);
109
110 if !status.is_client_error() && !status.is_server_error() {
111 let content = resp.text().await?;
112 match content_type {
113 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserDto`"))),
115 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::UserDto`")))),
116 }
117 } else {
118 let content = resp.text().await?;
119 let entity: Option<AddUserError> = serde_json::from_str(&content).ok();
120 Err(Error::ResponseError(ResponseContent { status, content, entity }))
121 }
122}
123
124pub async fn delete_user_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteUserByIdError>> {
126 let p_path_id = id;
128
129 let uri_str = format!("{}/api/v2/users/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
130 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
131
132 if let Some(ref user_agent) = configuration.user_agent {
133 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134 }
135 if let Some(ref apikey) = configuration.api_key {
136 let key = apikey.key.clone();
137 let value = match apikey.prefix {
138 Some(ref prefix) => format!("{} {}", prefix, key),
139 None => key,
140 };
141 req_builder = req_builder.header("X-API-Key", value);
142 };
143 if let Some(ref auth_conf) = configuration.basic_auth {
144 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.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
152 if !status.is_client_error() && !status.is_server_error() {
153 Ok(())
154 } else {
155 let content = resp.text().await?;
156 let entity: Option<DeleteUserByIdError> = serde_json::from_str(&content).ok();
157 Err(Error::ResponseError(ResponseContent { status, content, entity }))
158 }
159}
160
161pub async fn get_authentication_activity(configuration: &configuration::Configuration, unpaged: Option<bool>, page: Option<i32>, size: Option<i32>, sort: Option<Vec<String>>) -> Result<models::PageAuthenticationActivityDto, Error<GetAuthenticationActivityError>> {
163 let p_query_unpaged = unpaged;
165 let p_query_page = page;
166 let p_query_size = size;
167 let p_query_sort = sort;
168
169 let uri_str = format!("{}/api/v2/users/authentication-activity", configuration.base_path);
170 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
171
172 if let Some(ref param_value) = p_query_unpaged {
173 req_builder = req_builder.query(&[("unpaged", ¶m_value.to_string())]);
174 }
175 if let Some(ref param_value) = p_query_page {
176 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
177 }
178 if let Some(ref param_value) = p_query_size {
179 req_builder = req_builder.query(&[("size", ¶m_value.to_string())]);
180 }
181 if let Some(ref param_value) = p_query_sort {
182 req_builder = match "multi" {
183 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("sort".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
184 _ => req_builder.query(&[("sort", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
185 };
186 }
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 if let Some(ref apikey) = configuration.api_key {
191 let key = apikey.key.clone();
192 let value = match apikey.prefix {
193 Some(ref prefix) => format!("{} {}", prefix, key),
194 None => key,
195 };
196 req_builder = req_builder.header("X-API-Key", value);
197 };
198 if let Some(ref auth_conf) = configuration.basic_auth {
199 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
200 };
201
202 let req = req_builder.build()?;
203 let resp = configuration.client.execute(req).await?;
204
205 let status = resp.status();
206 let content_type = resp
207 .headers()
208 .get("content-type")
209 .and_then(|v| v.to_str().ok())
210 .unwrap_or("application/octet-stream");
211 let content_type = super::ContentType::from(content_type);
212
213 if !status.is_client_error() && !status.is_server_error() {
214 let content = resp.text().await?;
215 match content_type {
216 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
217 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PageAuthenticationActivityDto`"))),
218 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::PageAuthenticationActivityDto`")))),
219 }
220 } else {
221 let content = resp.text().await?;
222 let entity: Option<GetAuthenticationActivityError> = serde_json::from_str(&content).ok();
223 Err(Error::ResponseError(ResponseContent { status, content, entity }))
224 }
225}
226
227pub async fn get_latest_authentication_activity_by_user_id(configuration: &configuration::Configuration, id: &str, apikey_id: Option<&str>) -> Result<models::AuthenticationActivityDto, Error<GetLatestAuthenticationActivityByUserIdError>> {
229 let p_path_id = id;
231 let p_query_apikey_id = apikey_id;
232
233 let uri_str = format!("{}/api/v2/users/{id}/authentication-activity/latest", configuration.base_path, id=crate::apis::urlencode(p_path_id));
234 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
235
236 if let Some(ref param_value) = p_query_apikey_id {
237 req_builder = req_builder.query(&[("apikey_id", ¶m_value.to_string())]);
238 }
239 if let Some(ref user_agent) = configuration.user_agent {
240 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
241 }
242 if let Some(ref apikey) = configuration.api_key {
243 let key = apikey.key.clone();
244 let value = match apikey.prefix {
245 Some(ref prefix) => format!("{} {}", prefix, key),
246 None => key,
247 };
248 req_builder = req_builder.header("X-API-Key", value);
249 };
250 if let Some(ref auth_conf) = configuration.basic_auth {
251 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
252 };
253
254 let req = req_builder.build()?;
255 let resp = configuration.client.execute(req).await?;
256
257 let status = resp.status();
258 let content_type = resp
259 .headers()
260 .get("content-type")
261 .and_then(|v| v.to_str().ok())
262 .unwrap_or("application/octet-stream");
263 let content_type = super::ContentType::from(content_type);
264
265 if !status.is_client_error() && !status.is_server_error() {
266 let content = resp.text().await?;
267 match content_type {
268 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
269 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AuthenticationActivityDto`"))),
270 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::AuthenticationActivityDto`")))),
271 }
272 } else {
273 let content = resp.text().await?;
274 let entity: Option<GetLatestAuthenticationActivityByUserIdError> = serde_json::from_str(&content).ok();
275 Err(Error::ResponseError(ResponseContent { status, content, entity }))
276 }
277}
278
279pub async fn get_users(configuration: &configuration::Configuration, ) -> Result<Vec<models::UserDto>, Error<GetUsersError>> {
281
282 let uri_str = format!("{}/api/v2/users", configuration.base_path);
283 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
284
285 if let Some(ref user_agent) = configuration.user_agent {
286 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
287 }
288 if let Some(ref apikey) = configuration.api_key {
289 let key = apikey.key.clone();
290 let value = match apikey.prefix {
291 Some(ref prefix) => format!("{} {}", prefix, key),
292 None => key,
293 };
294 req_builder = req_builder.header("X-API-Key", value);
295 };
296 if let Some(ref auth_conf) = configuration.basic_auth {
297 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
298 };
299
300 let req = req_builder.build()?;
301 let resp = configuration.client.execute(req).await?;
302
303 let status = resp.status();
304 let content_type = resp
305 .headers()
306 .get("content-type")
307 .and_then(|v| v.to_str().ok())
308 .unwrap_or("application/octet-stream");
309 let content_type = super::ContentType::from(content_type);
310
311 if !status.is_client_error() && !status.is_server_error() {
312 let content = resp.text().await?;
313 match content_type {
314 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
315 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::UserDto>`"))),
316 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::UserDto>`")))),
317 }
318 } else {
319 let content = resp.text().await?;
320 let entity: Option<GetUsersError> = serde_json::from_str(&content).ok();
321 Err(Error::ResponseError(ResponseContent { status, content, entity }))
322 }
323}
324
325pub async fn update_password_by_user_id(configuration: &configuration::Configuration, id: &str, password_update_dto: models::PasswordUpdateDto) -> Result<(), Error<UpdatePasswordByUserIdError>> {
327 let p_path_id = id;
329 let p_body_password_update_dto = password_update_dto;
330
331 let uri_str = format!("{}/api/v2/users/{id}/password", configuration.base_path, id=crate::apis::urlencode(p_path_id));
332 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
333
334 if let Some(ref user_agent) = configuration.user_agent {
335 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336 }
337 if let Some(ref apikey) = configuration.api_key {
338 let key = apikey.key.clone();
339 let value = match apikey.prefix {
340 Some(ref prefix) => format!("{} {}", prefix, key),
341 None => key,
342 };
343 req_builder = req_builder.header("X-API-Key", value);
344 };
345 if let Some(ref auth_conf) = configuration.basic_auth {
346 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
347 };
348 req_builder = req_builder.json(&p_body_password_update_dto);
349
350 let req = req_builder.build()?;
351 let resp = configuration.client.execute(req).await?;
352
353 let status = resp.status();
354
355 if !status.is_client_error() && !status.is_server_error() {
356 Ok(())
357 } else {
358 let content = resp.text().await?;
359 let entity: Option<UpdatePasswordByUserIdError> = serde_json::from_str(&content).ok();
360 Err(Error::ResponseError(ResponseContent { status, content, entity }))
361 }
362}
363
364pub async fn update_user_by_id(configuration: &configuration::Configuration, id: &str, user_update_dto: models::UserUpdateDto) -> Result<(), Error<UpdateUserByIdError>> {
366 let p_path_id = id;
368 let p_body_user_update_dto = user_update_dto;
369
370 let uri_str = format!("{}/api/v2/users/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
371 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
372
373 if let Some(ref user_agent) = configuration.user_agent {
374 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
375 }
376 if let Some(ref apikey) = configuration.api_key {
377 let key = apikey.key.clone();
378 let value = match apikey.prefix {
379 Some(ref prefix) => format!("{} {}", prefix, key),
380 None => key,
381 };
382 req_builder = req_builder.header("X-API-Key", value);
383 };
384 if let Some(ref auth_conf) = configuration.basic_auth {
385 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
386 };
387 req_builder = req_builder.json(&p_body_user_update_dto);
388
389 let req = req_builder.build()?;
390 let resp = configuration.client.execute(req).await?;
391
392 let status = resp.status();
393
394 if !status.is_client_error() && !status.is_server_error() {
395 Ok(())
396 } else {
397 let content = resp.text().await?;
398 let entity: Option<UpdateUserByIdError> = serde_json::from_str(&content).ok();
399 Err(Error::ResponseError(ResponseContent { status, content, entity }))
400 }
401}
402