Skip to main content

rocie_client/apis/
api_get_auth_user_api.rs

1// rocie - An enterprise grocery management system
2//
3// Copyright (C) 2026 Benedikt Peetz <benedikt.peetz@b-peetz.de>
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6// This file is part of Rocie.
7//
8// You should have received a copy of the License along with this program.
9// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
10
11/*
12 * rocie-server
13 *
14 * An enterprise grocery management system - server
15 *
16 * The version of the OpenAPI document: 0.1.0
17 * Contact: benedikt.peetz@b-peetz.de
18 * Generated by: https://openapi-generator.tech
19 */
20
21use super::{ContentType, Error, configuration};
22use crate::{apis::ResponseContent, models};
23use reqwest;
24use serde::{Deserialize, Serialize, de::Error as _};
25
26/// struct for typed errors of method [`user_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum UserByIdError {
30    Status401(),
31    Status403(),
32    Status404(),
33    Status500(String),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`users`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UsersError {
41    Status401(),
42    Status500(String),
43    UnknownValue(serde_json::Value),
44}
45
46pub async fn user_by_id(
47    configuration: &configuration::Configuration,
48    id: models::UserId,
49) -> Result<models::User, Error<UserByIdError>> {
50    // add a prefix to parameters to efficiently prevent name collisions
51    let p_path_id = id;
52
53    let uri_str = format!(
54        "{}/user/{id}",
55        configuration.base_path,
56        id = p_path_id.to_string()
57    );
58    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60    if let Some(ref user_agent) = configuration.user_agent {
61        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
62    }
63
64    let req = req_builder.build()?;
65    let resp = configuration.client.execute(req).await?;
66
67    let status = resp.status();
68    let content_type = resp
69        .headers()
70        .get("content-type")
71        .and_then(|v| v.to_str().ok())
72        .unwrap_or("application/octet-stream");
73    let content_type = super::ContentType::from(content_type);
74
75    if !status.is_client_error() && !status.is_server_error() {
76        let content = resp.text().await?;
77        match content_type {
78            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
79            ContentType::Text => {
80                return Err(Error::from(serde_json::Error::custom(
81                    "Received `text/plain` content type response that cannot be converted to `models::User`",
82                )));
83            }
84            ContentType::Unsupported(unknown_type) => {
85                return Err(Error::from(serde_json::Error::custom(format!(
86                    "Received `{unknown_type}` content type response that cannot be converted to `models::User`"
87                ))));
88            }
89        }
90    } else {
91        let content = resp.text().await?;
92        let entity: Option<UserByIdError> = serde_json::from_str(&content).ok();
93        Err(Error::ResponseError(ResponseContent {
94            status,
95            content,
96            entity,
97        }))
98    }
99}
100
101pub async fn users(
102    configuration: &configuration::Configuration,
103) -> Result<Vec<models::User>, Error<UsersError>> {
104    let uri_str = format!("{}/users", configuration.base_path);
105    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
106
107    if let Some(ref user_agent) = configuration.user_agent {
108        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
109    }
110
111    let req = req_builder.build()?;
112    let resp = configuration.client.execute(req).await?;
113
114    let status = resp.status();
115    let content_type = resp
116        .headers()
117        .get("content-type")
118        .and_then(|v| v.to_str().ok())
119        .unwrap_or("application/octet-stream");
120    let content_type = super::ContentType::from(content_type);
121
122    if !status.is_client_error() && !status.is_server_error() {
123        let content = resp.text().await?;
124        match content_type {
125            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126            ContentType::Text => {
127                return Err(Error::from(serde_json::Error::custom(
128                    "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::User&gt;`",
129                )));
130            }
131            ContentType::Unsupported(unknown_type) => {
132                return Err(Error::from(serde_json::Error::custom(format!(
133                    "Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::User&gt;`"
134                ))));
135            }
136        }
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<UsersError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent {
141            status,
142            content,
143            entity,
144        }))
145    }
146}