Skip to main content

rocie_client/apis/
api_set_auth_barcode_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 [`buy_barcode`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum BuyBarcodeError {
30    Status401(),
31    Status404(),
32    Status500(String),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`consume_barcode`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum ConsumeBarcodeError {
40    Status401(),
41    Status404(),
42    Status500(String),
43    UnknownValue(serde_json::Value),
44}
45
46pub async fn buy_barcode(
47    configuration: &configuration::Configuration,
48    barcode_id: models::BarcodeId,
49    times: u32,
50) -> Result<(), Error<BuyBarcodeError>> {
51    // add a prefix to parameters to efficiently prevent name collisions
52    let p_path_barcode_id = barcode_id;
53    let p_path_times = times;
54
55    let uri_str = format!(
56        "{}/barcode/{barcode_id}/buy/{times}",
57        configuration.base_path,
58        barcode_id = p_path_barcode_id.to_string(),
59        times = p_path_times
60    );
61    let mut req_builder = configuration
62        .client
63        .request(reqwest::Method::POST, &uri_str);
64
65    if let Some(ref user_agent) = configuration.user_agent {
66        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67    }
68
69    let req = req_builder.build()?;
70    let resp = configuration.client.execute(req).await?;
71
72    let status = resp.status();
73
74    if !status.is_client_error() && !status.is_server_error() {
75        Ok(())
76    } else {
77        let content = resp.text().await?;
78        let entity: Option<BuyBarcodeError> = serde_json::from_str(&content).ok();
79        Err(Error::ResponseError(ResponseContent {
80            status,
81            content,
82            entity,
83        }))
84    }
85}
86
87pub async fn consume_barcode(
88    configuration: &configuration::Configuration,
89    id: models::BarcodeId,
90    unit_amount: models::UnitAmount,
91) -> Result<(), Error<ConsumeBarcodeError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_path_id = id;
94    let p_body_unit_amount = unit_amount;
95
96    let uri_str = format!(
97        "{}/barcode/{id}/consume",
98        configuration.base_path,
99        id = p_path_id.to_string()
100    );
101    let mut req_builder = configuration
102        .client
103        .request(reqwest::Method::POST, &uri_str);
104
105    if let Some(ref user_agent) = configuration.user_agent {
106        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
107    }
108    req_builder = req_builder.json(&p_body_unit_amount);
109
110    let req = req_builder.build()?;
111    let resp = configuration.client.execute(req).await?;
112
113    let status = resp.status();
114
115    if !status.is_client_error() && !status.is_server_error() {
116        Ok(())
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<ConsumeBarcodeError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent {
121            status,
122            content,
123            entity,
124        }))
125    }
126}