Skip to main content

rocie_client/apis/
api_get_auth_inventory_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 [`amount_by_id`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum AmountByIdError {
30    Status401(),
31    Status404(),
32    Status500(String),
33    UnknownValue(serde_json::Value),
34}
35
36pub async fn amount_by_id(
37    configuration: &configuration::Configuration,
38    id: models::ProductId,
39) -> Result<models::ProductAmount, Error<AmountByIdError>> {
40    // add a prefix to parameters to efficiently prevent name collisions
41    let p_path_id = id;
42
43    let uri_str = format!(
44        "{}/inventory/{id}",
45        configuration.base_path,
46        id = p_path_id.to_string()
47    );
48    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
49
50    if let Some(ref user_agent) = configuration.user_agent {
51        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52    }
53
54    let req = req_builder.build()?;
55    let resp = configuration.client.execute(req).await?;
56
57    let status = resp.status();
58    let content_type = resp
59        .headers()
60        .get("content-type")
61        .and_then(|v| v.to_str().ok())
62        .unwrap_or("application/octet-stream");
63    let content_type = super::ContentType::from(content_type);
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        match content_type {
68            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69            ContentType::Text => {
70                return Err(Error::from(serde_json::Error::custom(
71                    "Received `text/plain` content type response that cannot be converted to `models::ProductAmount`",
72                )));
73            }
74            ContentType::Unsupported(unknown_type) => {
75                return Err(Error::from(serde_json::Error::custom(format!(
76                    "Received `{unknown_type}` content type response that cannot be converted to `models::ProductAmount`"
77                ))));
78            }
79        }
80    } else {
81        let content = resp.text().await?;
82        let entity: Option<AmountByIdError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent {
84            status,
85            content,
86            entity,
87        }))
88    }
89}