Skip to main content

rocie_client/apis/
api_get_auth_unit_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 [`unit_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum UnitByIdError {
30    Status401(),
31    Status404(),
32    Status500(String),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`units`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum UnitsError {
40    Status401(),
41    Status500(String),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`units_by_property_id`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UnitsByPropertyIdError {
49    Status401(),
50    Status500(String),
51    UnknownValue(serde_json::Value),
52}
53
54pub async fn unit_by_id(
55    configuration: &configuration::Configuration,
56    id: models::UnitId,
57) -> Result<models::Unit, Error<UnitByIdError>> {
58    // add a prefix to parameters to efficiently prevent name collisions
59    let p_path_id = id;
60
61    let uri_str = format!(
62        "{}/unit/{id}",
63        configuration.base_path,
64        id = p_path_id.to_string()
65    );
66    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
67
68    if let Some(ref user_agent) = configuration.user_agent {
69        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70    }
71
72    let req = req_builder.build()?;
73    let resp = configuration.client.execute(req).await?;
74
75    let status = resp.status();
76    let content_type = resp
77        .headers()
78        .get("content-type")
79        .and_then(|v| v.to_str().ok())
80        .unwrap_or("application/octet-stream");
81    let content_type = super::ContentType::from(content_type);
82
83    if !status.is_client_error() && !status.is_server_error() {
84        let content = resp.text().await?;
85        match content_type {
86            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
87            ContentType::Text => {
88                return Err(Error::from(serde_json::Error::custom(
89                    "Received `text/plain` content type response that cannot be converted to `models::Unit`",
90                )));
91            }
92            ContentType::Unsupported(unknown_type) => {
93                return Err(Error::from(serde_json::Error::custom(format!(
94                    "Received `{unknown_type}` content type response that cannot be converted to `models::Unit`"
95                ))));
96            }
97        }
98    } else {
99        let content = resp.text().await?;
100        let entity: Option<UnitByIdError> = serde_json::from_str(&content).ok();
101        Err(Error::ResponseError(ResponseContent {
102            status,
103            content,
104            entity,
105        }))
106    }
107}
108
109pub async fn units(
110    configuration: &configuration::Configuration,
111) -> Result<Vec<models::Unit>, Error<UnitsError>> {
112    let uri_str = format!("{}/units/", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123    let content_type = resp
124        .headers()
125        .get("content-type")
126        .and_then(|v| v.to_str().ok())
127        .unwrap_or("application/octet-stream");
128    let content_type = super::ContentType::from(content_type);
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        match content_type {
133            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134            ContentType::Text => {
135                return Err(Error::from(serde_json::Error::custom(
136                    "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Unit&gt;`",
137                )));
138            }
139            ContentType::Unsupported(unknown_type) => {
140                return Err(Error::from(serde_json::Error::custom(format!(
141                    "Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Unit&gt;`"
142                ))));
143            }
144        }
145    } else {
146        let content = resp.text().await?;
147        let entity: Option<UnitsError> = serde_json::from_str(&content).ok();
148        Err(Error::ResponseError(ResponseContent {
149            status,
150            content,
151            entity,
152        }))
153    }
154}
155
156pub async fn units_by_property_id(
157    configuration: &configuration::Configuration,
158    id: models::UnitPropertyId,
159) -> Result<Vec<models::Unit>, Error<UnitsByPropertyIdError>> {
160    // add a prefix to parameters to efficiently prevent name collisions
161    let p_path_id = id;
162
163    let uri_str = format!(
164        "{}/units-by-property/{id}",
165        configuration.base_path,
166        id = p_path_id.to_string()
167    );
168    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
169
170    if let Some(ref user_agent) = configuration.user_agent {
171        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172    }
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178    let content_type = resp
179        .headers()
180        .get("content-type")
181        .and_then(|v| v.to_str().ok())
182        .unwrap_or("application/octet-stream");
183    let content_type = super::ContentType::from(content_type);
184
185    if !status.is_client_error() && !status.is_server_error() {
186        let content = resp.text().await?;
187        match content_type {
188            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189            ContentType::Text => {
190                return Err(Error::from(serde_json::Error::custom(
191                    "Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Unit&gt;`",
192                )));
193            }
194            ContentType::Unsupported(unknown_type) => {
195                return Err(Error::from(serde_json::Error::custom(format!(
196                    "Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::Unit&gt;`"
197                ))));
198            }
199        }
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<UnitsByPropertyIdError> = serde_json::from_str(&content).ok();
203        Err(Error::ResponseError(ResponseContent {
204            status,
205            content,
206            entity,
207        }))
208    }
209}