diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:35:35 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-28 16:35:35 +0100 |
| commit | a479685602347b473d74f99f492e5e85d7afde94 (patch) | |
| tree | ed7eea0fbab0a9f33d959345719d638271539da0 /crates/rocie-client/src/apis | |
| parent | feat(crates/rocie-cli): Add support for product parents (diff) | |
| download | server-a479685602347b473d74f99f492e5e85d7afde94.zip | |
chore(crates/rocie-client): Re-generate
Diffstat (limited to 'crates/rocie-client/src/apis')
| -rw-r--r-- | crates/rocie-client/src/apis/api_get_product_api.rs | 144 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/api_get_product_parent_api.rs | 146 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/api_get_recipe_api.rs | 105 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/api_get_unit_api.rs | 44 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/api_set_product_parent_api.rs | 63 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/api_set_recipe_api.rs | 63 | ||||
| -rw-r--r-- | crates/rocie-client/src/apis/mod.rs | 4 |
7 files changed, 564 insertions, 5 deletions
diff --git a/crates/rocie-client/src/apis/api_get_product_api.rs b/crates/rocie-client/src/apis/api_get_product_api.rs index 2e18d8a..a4bf9b8 100644 --- a/crates/rocie-client/src/apis/api_get_product_api.rs +++ b/crates/rocie-client/src/apis/api_get_product_api.rs @@ -41,10 +41,36 @@ pub enum ProductSuggestionByNameError { UnknownValue(serde_json::Value), } -/// struct for typed errors of method [`products`] +/// struct for typed errors of method [`products_by_product_parent_id_direct`] #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -pub enum ProductsError { +pub enum ProductsByProductParentIdDirectError { + Status404(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`products_by_product_parent_id_indirect`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductsByProductParentIdIndirectError { + Status404(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`products_in_storage`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductsInStorageError { + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`products_registered`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductsRegisteredError { Status500(String), UnknownValue(serde_json::Value), } @@ -158,9 +184,117 @@ pub async fn product_suggestion_by_name(configuration: &configuration::Configura } } -pub async fn products(configuration: &configuration::Configuration, ) -> Result<Vec<models::Product>, Error<ProductsError>> { +/// This will only return products directly associated with this product parent id +pub async fn products_by_product_parent_id_direct(configuration: &configuration::Configuration, id: models::ProductParentId) -> Result<Vec<models::Product>, Error<ProductsByProductParentIdDirectError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/product/by-product-parent-id-direct/{id}", configuration.base_path, id=p_id.to_string()); + 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<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 `Vec<models::Product>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductsByProductParentIdDirectError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +/// This will also return all products below this product parent id +pub async fn products_by_product_parent_id_indirect(configuration: &configuration::Configuration, id: models::ProductParentId) -> Result<Vec<models::Product>, Error<ProductsByProductParentIdIndirectError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/product/by-product-parent-id-indirect/{id}", configuration.base_path, id=p_id.to_string()); + 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<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 `Vec<models::Product>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductsByProductParentIdIndirectError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn products_in_storage(configuration: &configuration::Configuration, ) -> Result<Vec<models::Product>, Error<ProductsInStorageError>> { + + let uri_str = format!("{}/products_in_storage/", 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<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 `Vec<models::Product>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductsInStorageError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn products_registered(configuration: &configuration::Configuration, ) -> Result<Vec<models::Product>, Error<ProductsRegisteredError>> { - let uri_str = format!("{}/products/", configuration.base_path); + let uri_str = format!("{}/products_registered/", configuration.base_path); let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); if let Some(ref user_agent) = configuration.user_agent { @@ -187,7 +321,7 @@ pub async fn products(configuration: &configuration::Configuration, ) -> Result< } } else { let content = resp.text().await?; - let entity: Option<ProductsError> = serde_json::from_str(&content).ok(); + let entity: Option<ProductsRegisteredError> = serde_json::from_str(&content).ok(); Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/crates/rocie-client/src/apis/api_get_product_parent_api.rs b/crates/rocie-client/src/apis/api_get_product_parent_api.rs new file mode 100644 index 0000000..6adc6e1 --- /dev/null +++ b/crates/rocie-client/src/apis/api_get_product_parent_api.rs @@ -0,0 +1,146 @@ +/* + * rocie-server + * + * An enterprise grocery management system - server + * + * 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_parents`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductParentsError { + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`product_parents_toplevel`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductParentsToplevelError { + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`product_parents_under`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductParentsUnderError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn product_parents(configuration: &configuration::Configuration, ) -> Result<Vec<models::ProductParent>, Error<ProductParentsError>> { + + let uri_str = format!("{}/product_parents/", 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<models::ProductParent>`"))), + 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<models::ProductParent>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductParentsError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn product_parents_toplevel(configuration: &configuration::Configuration, ) -> Result<Vec<models::ProductParent>, Error<ProductParentsToplevelError>> { + + let uri_str = format!("{}/product_parents_toplevel/", 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<models::ProductParent>`"))), + 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<models::ProductParent>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductParentsToplevelError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn product_parents_under(configuration: &configuration::Configuration, id: models::ProductParentId) -> Result<Vec<models::ProductParent>, Error<ProductParentsUnderError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/product_parents_under/{id}", configuration.base_path, id=p_id.to_string()); + 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<models::ProductParent>`"))), + 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<models::ProductParent>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<ProductParentsUnderError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/crates/rocie-client/src/apis/api_get_recipe_api.rs b/crates/rocie-client/src/apis/api_get_recipe_api.rs new file mode 100644 index 0000000..f29a2ce --- /dev/null +++ b/crates/rocie-client/src/apis/api_get_recipe_api.rs @@ -0,0 +1,105 @@ +/* + * rocie-server + * + * An enterprise grocery management system - server + * + * 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 [`recipe_by_id`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RecipeByIdError { + Status404(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`recipes`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RecipesError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn recipe_by_id(configuration: &configuration::Configuration, id: models::RecipeId) -> Result<models::Recipe, Error<RecipeByIdError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/recipe/by-id/{id}", configuration.base_path, id=p_id.to_string()); + 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::Recipe`"))), + 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::Recipe`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<RecipeByIdError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn recipes(configuration: &configuration::Configuration, ) -> Result<models::Recipe, Error<RecipesError>> { + + let uri_str = format!("{}/recipe/all", 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 `models::Recipe`"))), + 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::Recipe`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<RecipesError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/crates/rocie-client/src/apis/api_get_unit_api.rs b/crates/rocie-client/src/apis/api_get_unit_api.rs index 927b883..df25b47 100644 --- a/crates/rocie-client/src/apis/api_get_unit_api.rs +++ b/crates/rocie-client/src/apis/api_get_unit_api.rs @@ -32,6 +32,14 @@ pub enum UnitsError { UnknownValue(serde_json::Value), } +/// struct for typed errors of method [`units_by_property_id`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UnitsByPropertyIdError { + Status500(String), + UnknownValue(serde_json::Value), +} + pub async fn unit_by_id(configuration: &configuration::Configuration, id: models::UnitId) -> Result<models::Unit, Error<UnitByIdError>> { // add a prefix to parameters to efficiently prevent name collisions @@ -103,3 +111,39 @@ pub async fn units(configuration: &configuration::Configuration, ) -> Result<Vec } } +pub async fn units_by_property_id(configuration: &configuration::Configuration, id: models::UnitPropertyId) -> Result<Vec<models::Unit>, Error<UnitsByPropertyIdError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/units-by-property/{id}", configuration.base_path, id=p_id.to_string()); + 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<models::Unit>`"))), + 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<models::Unit>`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<UnitsByPropertyIdError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/crates/rocie-client/src/apis/api_set_product_parent_api.rs b/crates/rocie-client/src/apis/api_set_product_parent_api.rs new file mode 100644 index 0000000..a537941 --- /dev/null +++ b/crates/rocie-client/src/apis/api_set_product_parent_api.rs @@ -0,0 +1,63 @@ +/* + * rocie-server + * + * An enterprise grocery management system - server + * + * 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 [`register_product_parent`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RegisterProductParentError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn register_product_parent(configuration: &configuration::Configuration, product_parent_stub: models::ProductParentStub) -> Result<models::ProductParentId, Error<RegisterProductParentError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_product_parent_stub = product_parent_stub; + + let uri_str = format!("{}/product_parent/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_parent_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 `models::ProductParentId`"))), + 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::ProductParentId`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<RegisterProductParentError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/crates/rocie-client/src/apis/api_set_recipe_api.rs b/crates/rocie-client/src/apis/api_set_recipe_api.rs new file mode 100644 index 0000000..519f90e --- /dev/null +++ b/crates/rocie-client/src/apis/api_set_recipe_api.rs @@ -0,0 +1,63 @@ +/* + * rocie-server + * + * An enterprise grocery management system - server + * + * 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 [`add_recipe`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum AddRecipeError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn add_recipe(configuration: &configuration::Configuration, recipe_stub: models::RecipeStub) -> Result<models::RecipeId, Error<AddRecipeError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_recipe_stub = recipe_stub; + + let uri_str = format!("{}/recipe/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_recipe_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 `models::RecipeId`"))), + 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::RecipeId`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<AddRecipeError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + diff --git a/crates/rocie-client/src/apis/mod.rs b/crates/rocie-client/src/apis/mod.rs index 0853432..13e70ba 100644 --- a/crates/rocie-client/src/apis/mod.rs +++ b/crates/rocie-client/src/apis/mod.rs @@ -113,10 +113,14 @@ impl From<&str> for ContentType { pub mod api_get_inventory_api; pub mod api_get_product_api; +pub mod api_get_product_parent_api; +pub mod api_get_recipe_api; pub mod api_get_unit_api; pub mod api_get_unit_property_api; pub mod api_set_barcode_api; pub mod api_set_product_api; +pub mod api_set_product_parent_api; +pub mod api_set_recipe_api; pub mod api_set_unit_api; pub mod api_set_unit_property_api; |
