aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-client/src')
-rw-r--r--crates/rocie-client/src/apis/api_get_api.rs103
-rw-r--r--crates/rocie-client/src/apis/api_set_api.rs96
-rw-r--r--crates/rocie-client/src/apis/configuration.rs51
-rw-r--r--crates/rocie-client/src/apis/mod.rs117
-rw-r--r--crates/rocie-client/src/lib.rs11
-rw-r--r--crates/rocie-client/src/models/bar_code.rs27
-rw-r--r--crates/rocie-client/src/models/barcode.rs30
-rw-r--r--crates/rocie-client/src/models/mod.rs8
-rw-r--r--crates/rocie-client/src/models/product.rs36
-rw-r--r--crates/rocie-client/src/models/product_one_of.rs27
-rw-r--r--crates/rocie-client/src/models/product_one_of_1.rs27
-rw-r--r--crates/rocie-client/src/models/product_stub.rs33
-rw-r--r--crates/rocie-client/src/models/unit_amount.rs30
13 files changed, 596 insertions, 0 deletions
diff --git a/crates/rocie-client/src/apis/api_get_api.rs b/crates/rocie-client/src/apis/api_get_api.rs
new file mode 100644
index 0000000..3217717
--- /dev/null
+++ b/crates/rocie-client/src/apis/api_get_api.rs
@@ -0,0 +1,103 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+
+use reqwest;
+use serde::{Deserialize, Serialize, de::Error as _};
+use crate::{apis::ResponseContent, models};
+use super::{Error, configuration, ContentType};
+
+
+/// struct for typed errors of method [`product_by_id`]
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum ProductByIdError {
+ Status404(),
+ UnknownValue(serde_json::Value),
+}
+
+/// struct for typed errors of method [`products`]
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum ProductsError {
+ UnknownValue(serde_json::Value),
+}
+
+
+pub async fn product_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Product, Error<ProductByIdError>> {
+ // add a prefix to parameters to efficiently prevent name collisions
+ let p_id = id;
+
+ let uri_str = format!("{}/product/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
+ let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
+
+ if let Some(ref user_agent) = configuration.user_agent {
+ req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
+ }
+
+ let req = req_builder.build()?;
+ let resp = configuration.client.execute(req).await?;
+
+ let status = resp.status();
+ let content_type = resp
+ .headers()
+ .get("content-type")
+ .and_then(|v| v.to_str().ok())
+ .unwrap_or("application/octet-stream");
+ let content_type = super::ContentType::from(content_type);
+
+ if !status.is_client_error() && !status.is_server_error() {
+ let content = resp.text().await?;
+ match content_type {
+ ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
+ ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Product`"))),
+ 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::Product`")))),
+ }
+ } else {
+ let content = resp.text().await?;
+ let entity: Option<ProductByIdError> = serde_json::from_str(&content).ok();
+ Err(Error::ResponseError(ResponseContent { status, content, entity }))
+ }
+}
+
+pub async fn products(configuration: &configuration::Configuration, ) -> Result<Vec<models::Product>, Error<ProductsError>> {
+
+ let uri_str = format!("{}/products/", configuration.base_path);
+ let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
+
+ if let Some(ref user_agent) = configuration.user_agent {
+ req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
+ }
+
+ let req = req_builder.build()?;
+ let resp = configuration.client.execute(req).await?;
+
+ let status = resp.status();
+ let content_type = resp
+ .headers()
+ .get("content-type")
+ .and_then(|v| v.to_str().ok())
+ .unwrap_or("application/octet-stream");
+ let content_type = super::ContentType::from(content_type);
+
+ if !status.is_client_error() && !status.is_server_error() {
+ let content = resp.text().await?;
+ match content_type {
+ ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
+ ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::Product&gt;`"))),
+ 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&lt;models::Product&gt;`")))),
+ }
+ } else {
+ let content = resp.text().await?;
+ let entity: Option<ProductsError> = serde_json::from_str(&content).ok();
+ Err(Error::ResponseError(ResponseContent { status, content, entity }))
+ }
+}
+
diff --git a/crates/rocie-client/src/apis/api_set_api.rs b/crates/rocie-client/src/apis/api_set_api.rs
new file mode 100644
index 0000000..7c0c414
--- /dev/null
+++ b/crates/rocie-client/src/apis/api_set_api.rs
@@ -0,0 +1,96 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+
+use reqwest;
+use serde::{Deserialize, Serialize, de::Error as _};
+use crate::{apis::ResponseContent, models};
+use super::{Error, configuration, ContentType};
+
+
+/// struct for typed errors of method [`associate_barcode`]
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum AssociateBarcodeError {
+ UnknownValue(serde_json::Value),
+}
+
+/// struct for typed errors of method [`register_product`]
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(untagged)]
+pub enum RegisterProductError {
+ UnknownValue(serde_json::Value),
+}
+
+
+pub async fn associate_barcode(configuration: &configuration::Configuration, id: &str, barcode: models::Barcode) -> Result<(), Error<AssociateBarcodeError>> {
+ // add a prefix to parameters to efficiently prevent name collisions
+ let p_id = id;
+ let p_barcode = barcode;
+
+ let uri_str = format!("{}/product/{id}/associate", configuration.base_path, id=crate::apis::urlencode(p_id));
+ let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
+
+ if let Some(ref user_agent) = configuration.user_agent {
+ req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
+ }
+ req_builder = req_builder.json(&p_barcode);
+
+ let req = req_builder.build()?;
+ let resp = configuration.client.execute(req).await?;
+
+ let status = resp.status();
+
+ if !status.is_client_error() && !status.is_server_error() {
+ Ok(())
+ } else {
+ let content = resp.text().await?;
+ let entity: Option<AssociateBarcodeError> = serde_json::from_str(&content).ok();
+ Err(Error::ResponseError(ResponseContent { status, content, entity }))
+ }
+}
+
+pub async fn register_product(configuration: &configuration::Configuration, product_stub: models::ProductStub) -> Result<uuid::Uuid, Error<RegisterProductError>> {
+ // add a prefix to parameters to efficiently prevent name collisions
+ let p_product_stub = product_stub;
+
+ let uri_str = format!("{}/product/new", configuration.base_path);
+ let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
+
+ if let Some(ref user_agent) = configuration.user_agent {
+ req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
+ }
+ req_builder = req_builder.json(&p_product_stub);
+
+ let req = req_builder.build()?;
+ let resp = configuration.client.execute(req).await?;
+
+ let status = resp.status();
+ let content_type = resp
+ .headers()
+ .get("content-type")
+ .and_then(|v| v.to_str().ok())
+ .unwrap_or("application/octet-stream");
+ let content_type = super::ContentType::from(content_type);
+
+ if !status.is_client_error() && !status.is_server_error() {
+ let content = resp.text().await?;
+ match content_type {
+ ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
+ ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `uuid::Uuid`"))),
+ ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `uuid::Uuid`")))),
+ }
+ } else {
+ let content = resp.text().await?;
+ let entity: Option<RegisterProductError> = serde_json::from_str(&content).ok();
+ Err(Error::ResponseError(ResponseContent { status, content, entity }))
+ }
+}
+
diff --git a/crates/rocie-client/src/apis/configuration.rs b/crates/rocie-client/src/apis/configuration.rs
new file mode 100644
index 0000000..a4fbb93
--- /dev/null
+++ b/crates/rocie-client/src/apis/configuration.rs
@@ -0,0 +1,51 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+
+
+#[derive(Debug, Clone)]
+pub struct Configuration {
+ pub base_path: String,
+ pub user_agent: Option<String>,
+ pub client: reqwest::Client,
+ pub basic_auth: Option<BasicAuth>,
+ pub oauth_access_token: Option<String>,
+ pub bearer_access_token: Option<String>,
+ pub api_key: Option<ApiKey>,
+}
+
+pub type BasicAuth = (String, Option<String>);
+
+#[derive(Debug, Clone)]
+pub struct ApiKey {
+ pub prefix: Option<String>,
+ pub key: String,
+}
+
+
+impl Configuration {
+ pub fn new() -> Configuration {
+ Configuration::default()
+ }
+}
+
+impl Default for Configuration {
+ fn default() -> Self {
+ Configuration {
+ base_path: "http://localhost".to_owned(),
+ user_agent: Some("OpenAPI-Generator/0.1.0/rust".to_owned()),
+ client: reqwest::Client::new(),
+ basic_auth: None,
+ oauth_access_token: None,
+ bearer_access_token: None,
+ api_key: None,
+ }
+ }
+}
diff --git a/crates/rocie-client/src/apis/mod.rs b/crates/rocie-client/src/apis/mod.rs
new file mode 100644
index 0000000..c3f990f
--- /dev/null
+++ b/crates/rocie-client/src/apis/mod.rs
@@ -0,0 +1,117 @@
+use std::error;
+use std::fmt;
+
+#[derive(Debug, Clone)]
+pub struct ResponseContent<T> {
+ pub status: reqwest::StatusCode,
+ pub content: String,
+ pub entity: Option<T>,
+}
+
+#[derive(Debug)]
+pub enum Error<T> {
+ Reqwest(reqwest::Error),
+ Serde(serde_json::Error),
+ Io(std::io::Error),
+ ResponseError(ResponseContent<T>),
+}
+
+impl <T> fmt::Display for Error<T> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let (module, e) = match self {
+ Error::Reqwest(e) => ("reqwest", e.to_string()),
+ Error::Serde(e) => ("serde", e.to_string()),
+ Error::Io(e) => ("IO", e.to_string()),
+ Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
+ };
+ write!(f, "error in {}: {}", module, e)
+ }
+}
+
+impl <T: fmt::Debug> error::Error for Error<T> {
+ fn source(&self) -> Option<&(dyn error::Error + 'static)> {
+ Some(match self {
+ Error::Reqwest(e) => e,
+ Error::Serde(e) => e,
+ Error::Io(e) => e,
+ Error::ResponseError(_) => return None,
+ })
+ }
+}
+
+impl <T> From<reqwest::Error> for Error<T> {
+ fn from(e: reqwest::Error) -> Self {
+ Error::Reqwest(e)
+ }
+}
+
+impl <T> From<serde_json::Error> for Error<T> {
+ fn from(e: serde_json::Error) -> Self {
+ Error::Serde(e)
+ }
+}
+
+impl <T> From<std::io::Error> for Error<T> {
+ fn from(e: std::io::Error) -> Self {
+ Error::Io(e)
+ }
+}
+
+pub fn urlencode<T: AsRef<str>>(s: T) -> String {
+ ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
+}
+
+pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
+ if let serde_json::Value::Object(object) = value {
+ let mut params = vec![];
+
+ for (key, value) in object {
+ match value {
+ serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
+ &format!("{}[{}]", prefix, key),
+ value,
+ )),
+ serde_json::Value::Array(array) => {
+ for (i, value) in array.iter().enumerate() {
+ params.append(&mut parse_deep_object(
+ &format!("{}[{}][{}]", prefix, key, i),
+ value,
+ ));
+ }
+ },
+ serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
+ _ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
+ }
+ }
+
+ return params;
+ }
+
+ unimplemented!("Only objects are supported with style=deepObject")
+}
+
+/// Internal use only
+/// A content type supported by this client.
+#[allow(dead_code)]
+enum ContentType {
+ Json,
+ Text,
+ Unsupported(String)
+}
+
+impl From<&str> for ContentType {
+ fn from(content_type: &str) -> Self {
+ if content_type.starts_with("application") && content_type.contains("json") {
+ return Self::Json;
+ } else if content_type.starts_with("text/plain") {
+ return Self::Text;
+ } else {
+ return Self::Unsupported(content_type.to_string());
+ }
+ }
+}
+
+pub mod api_get_api;
+pub mod api_set_api;
+
+pub mod configuration;
diff --git a/crates/rocie-client/src/lib.rs b/crates/rocie-client/src/lib.rs
new file mode 100644
index 0000000..e152062
--- /dev/null
+++ b/crates/rocie-client/src/lib.rs
@@ -0,0 +1,11 @@
+#![allow(unused_imports)]
+#![allow(clippy::too_many_arguments)]
+
+extern crate serde_repr;
+extern crate serde;
+extern crate serde_json;
+extern crate url;
+extern crate reqwest;
+
+pub mod apis;
+pub mod models;
diff --git a/crates/rocie-client/src/models/bar_code.rs b/crates/rocie-client/src/models/bar_code.rs
new file mode 100644
index 0000000..c8123a2
--- /dev/null
+++ b/crates/rocie-client/src/models/bar_code.rs
@@ -0,0 +1,27 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct BarCode {
+ #[serde(rename = "id")]
+ pub id: i64,
+}
+
+impl BarCode {
+ pub fn new(id: i64) -> BarCode {
+ BarCode {
+ id,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/barcode.rs b/crates/rocie-client/src/models/barcode.rs
new file mode 100644
index 0000000..7690be2
--- /dev/null
+++ b/crates/rocie-client/src/models/barcode.rs
@@ -0,0 +1,30 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Barcode {
+ #[serde(rename = "amount")]
+ pub amount: Box<models::UnitAmount>,
+ #[serde(rename = "id")]
+ pub id: i32,
+}
+
+impl Barcode {
+ pub fn new(amount: models::UnitAmount, id: i32) -> Barcode {
+ Barcode {
+ amount: Box::new(amount),
+ id,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/mod.rs b/crates/rocie-client/src/models/mod.rs
new file mode 100644
index 0000000..6c96c01
--- /dev/null
+++ b/crates/rocie-client/src/models/mod.rs
@@ -0,0 +1,8 @@
+pub mod barcode;
+pub use self::barcode::Barcode;
+pub mod product;
+pub use self::product::Product;
+pub mod product_stub;
+pub use self::product_stub::ProductStub;
+pub mod unit_amount;
+pub use self::unit_amount::UnitAmount;
diff --git a/crates/rocie-client/src/models/product.rs b/crates/rocie-client/src/models/product.rs
new file mode 100644
index 0000000..acdc6c6
--- /dev/null
+++ b/crates/rocie-client/src/models/product.rs
@@ -0,0 +1,36 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct Product {
+ #[serde(rename = "associated_bar_codes")]
+ pub associated_bar_codes: Vec<models::Barcode>,
+ #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
+ pub description: Option<Option<String>>,
+ #[serde(rename = "id")]
+ pub id: uuid::Uuid,
+ #[serde(rename = "name")]
+ pub name: String,
+}
+
+impl Product {
+ pub fn new(associated_bar_codes: Vec<models::Barcode>, id: uuid::Uuid, name: String) -> Product {
+ Product {
+ associated_bar_codes,
+ description: None,
+ id,
+ name,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/product_one_of.rs b/crates/rocie-client/src/models/product_one_of.rs
new file mode 100644
index 0000000..399c06b
--- /dev/null
+++ b/crates/rocie-client/src/models/product_one_of.rs
@@ -0,0 +1,27 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct ProductOneOf {
+ #[serde(rename = "Mass")]
+ pub mass: i64,
+}
+
+impl ProductOneOf {
+ pub fn new(mass: i64) -> ProductOneOf {
+ ProductOneOf {
+ mass,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/product_one_of_1.rs b/crates/rocie-client/src/models/product_one_of_1.rs
new file mode 100644
index 0000000..58e033f
--- /dev/null
+++ b/crates/rocie-client/src/models/product_one_of_1.rs
@@ -0,0 +1,27 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct ProductOneOf1 {
+ #[serde(rename = "Volume")]
+ pub volume: i64,
+}
+
+impl ProductOneOf1 {
+ pub fn new(volume: i64) -> ProductOneOf1 {
+ ProductOneOf1 {
+ volume,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/product_stub.rs b/crates/rocie-client/src/models/product_stub.rs
new file mode 100644
index 0000000..3849c18
--- /dev/null
+++ b/crates/rocie-client/src/models/product_stub.rs
@@ -0,0 +1,33 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct ProductStub {
+ #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
+ pub description: Option<Option<String>>,
+ #[serde(rename = "name")]
+ pub name: String,
+ #[serde(rename = "parent", skip_serializing_if = "Option::is_none")]
+ pub parent: Option<uuid::Uuid>,
+}
+
+impl ProductStub {
+ pub fn new(name: String) -> ProductStub {
+ ProductStub {
+ description: None,
+ name,
+ parent: None,
+ }
+ }
+}
+
diff --git a/crates/rocie-client/src/models/unit_amount.rs b/crates/rocie-client/src/models/unit_amount.rs
new file mode 100644
index 0000000..038adb0
--- /dev/null
+++ b/crates/rocie-client/src/models/unit_amount.rs
@@ -0,0 +1,30 @@
+/*
+ * rocie-server
+ *
+ * An enterprise grocery management system
+ *
+ * The version of the OpenAPI document: 0.1.0
+ * Contact: benedikt.peetz@b-peetz.de
+ * Generated by: https://openapi-generator.tech
+ */
+
+use crate::models;
+use serde::{Deserialize, Serialize};
+
+#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
+pub struct UnitAmount {
+ #[serde(rename = "unit")]
+ pub unit: String,
+ #[serde(rename = "value")]
+ pub value: i32,
+}
+
+impl UnitAmount {
+ pub fn new(unit: String, value: i32) -> UnitAmount {
+ UnitAmount {
+ unit,
+ value,
+ }
+ }
+}
+