diff options
Diffstat (limited to 'crates/rocie-client')
24 files changed, 754 insertions, 22 deletions
diff --git a/crates/rocie-client/.openapi-generator/FILES b/crates/rocie-client/.openapi-generator/FILES index f9b70e6..01b279c 100644 --- a/crates/rocie-client/.openapi-generator/FILES +++ b/crates/rocie-client/.openapi-generator/FILES @@ -1,15 +1,21 @@ .gitignore .travis.yml README.md -docs/ApiGetApi.md -docs/ApiSetApi.md +docs/ApiGetProductApi.md +docs/ApiGetUnitApi.md +docs/ApiSetProductApi.md +docs/ApiSetUnitApi.md docs/Barcode.md docs/Product.md docs/ProductStub.md +docs/Unit.md docs/UnitAmount.md +docs/UnitStub.md git_push.sh -src/apis/api_get_api.rs -src/apis/api_set_api.rs +src/apis/api_get_product_api.rs +src/apis/api_get_unit_api.rs +src/apis/api_set_product_api.rs +src/apis/api_set_unit_api.rs src/apis/configuration.rs src/apis/mod.rs src/lib.rs @@ -17,4 +23,6 @@ src/models/barcode.rs src/models/mod.rs src/models/product.rs src/models/product_stub.rs +src/models/unit.rs src/models/unit_amount.rs +src/models/unit_stub.rs diff --git a/crates/rocie-client/README.md b/crates/rocie-client/README.md index 7649325..26bacb1 100644 --- a/crates/rocie-client/README.md +++ b/crates/rocie-client/README.md @@ -26,10 +26,13 @@ All URIs are relative to *http://localhost* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*ApiGetApi* | [**product_by_id**](docs/ApiGetApi.md#product_by_id) | **GET** /product/{id} | Get Product by id -*ApiGetApi* | [**products**](docs/ApiGetApi.md#products) | **GET** /products/ | Return all registered products -*ApiSetApi* | [**associate_barcode**](docs/ApiSetApi.md#associate_barcode) | **POST** /product/{id}/associate | Associate a barcode with a product -*ApiSetApi* | [**register_product**](docs/ApiSetApi.md#register_product) | **POST** /product/new | Register a product +*ApiGetProductApi* | [**product_by_id**](docs/ApiGetProductApi.md#product_by_id) | **GET** /product/{id} | Get Product by id +*ApiGetProductApi* | [**products**](docs/ApiGetProductApi.md#products) | **GET** /products/ | Return all registered products +*ApiGetUnitApi* | [**unit_by_id**](docs/ApiGetUnitApi.md#unit_by_id) | **GET** /unit/{id} | Get Unit by id +*ApiGetUnitApi* | [**units**](docs/ApiGetUnitApi.md#units) | **GET** /units/ | Return all registered units +*ApiSetProductApi* | [**associate_barcode**](docs/ApiSetProductApi.md#associate_barcode) | **POST** /product/{id}/associate | Associate a barcode with a product +*ApiSetProductApi* | [**register_product**](docs/ApiSetProductApi.md#register_product) | **POST** /product/new | Register a product +*ApiSetUnitApi* | [**register_unit**](docs/ApiSetUnitApi.md#register_unit) | **POST** /unit/new | Register an Unit ## Documentation For Models @@ -37,7 +40,9 @@ Class | Method | HTTP request | Description - [Barcode](docs/Barcode.md) - [Product](docs/Product.md) - [ProductStub](docs/ProductStub.md) + - [Unit](docs/Unit.md) - [UnitAmount](docs/UnitAmount.md) + - [UnitStub](docs/UnitStub.md) To get access to the crate's generated documentation, use: diff --git a/crates/rocie-client/docs/ApiGetApi.md b/crates/rocie-client/docs/ApiGetApi.md index f2df94c..1ecfb75 100644 --- a/crates/rocie-client/docs/ApiGetApi.md +++ b/crates/rocie-client/docs/ApiGetApi.md @@ -32,7 +32,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json +- **Accept**: application/json, text/plain [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -57,7 +57,7 @@ No authorization required ### HTTP request headers - **Content-Type**: Not defined -- **Accept**: application/json +- **Accept**: application/json, text/plain [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/crates/rocie-client/docs/ApiGetProductApi.md b/crates/rocie-client/docs/ApiGetProductApi.md new file mode 100644 index 0000000..58955c6 --- /dev/null +++ b/crates/rocie-client/docs/ApiGetProductApi.md @@ -0,0 +1,63 @@ +# \ApiGetProductApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**product_by_id**](ApiGetProductApi.md#product_by_id) | **GET** /product/{id} | Get Product by id +[**products**](ApiGetProductApi.md#products) | **GET** /products/ | Return all registered products + + + +## product_by_id + +> models::Product product_by_id(id) +Get Product by id + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**id** | **uuid::Uuid** | Product id | [required] | + +### Return type + +[**models::Product**](Product.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## products + +> Vec<models::Product> products() +Return all registered products + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**Vec<models::Product>**](Product.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/crates/rocie-client/docs/ApiGetUnitApi.md b/crates/rocie-client/docs/ApiGetUnitApi.md new file mode 100644 index 0000000..3ac44c0 --- /dev/null +++ b/crates/rocie-client/docs/ApiGetUnitApi.md @@ -0,0 +1,63 @@ +# \ApiGetUnitApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**unit_by_id**](ApiGetUnitApi.md#unit_by_id) | **GET** /unit/{id} | Get Unit by id +[**units**](ApiGetUnitApi.md#units) | **GET** /units/ | Return all registered units + + + +## unit_by_id + +> models::Unit unit_by_id(id) +Get Unit by id + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**id** | **uuid::Uuid** | Unit id | [required] | + +### Return type + +[**models::Unit**](Unit.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## units + +> Vec<models::Unit> units() +Return all registered units + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +[**Vec<models::Unit>**](Unit.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/crates/rocie-client/docs/ApiSetApi.md b/crates/rocie-client/docs/ApiSetApi.md index 87f88b8..6129e50 100644 --- a/crates/rocie-client/docs/ApiSetApi.md +++ b/crates/rocie-client/docs/ApiSetApi.md @@ -33,7 +33,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: Not defined +- **Accept**: text/plain [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) @@ -61,7 +61,7 @@ No authorization required ### HTTP request headers - **Content-Type**: application/json -- **Accept**: application/json +- **Accept**: application/json, text/plain [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/crates/rocie-client/docs/ApiSetProductApi.md b/crates/rocie-client/docs/ApiSetProductApi.md new file mode 100644 index 0000000..6166887 --- /dev/null +++ b/crates/rocie-client/docs/ApiSetProductApi.md @@ -0,0 +1,67 @@ +# \ApiSetProductApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**associate_barcode**](ApiSetProductApi.md#associate_barcode) | **POST** /product/{id}/associate | Associate a barcode with a product +[**register_product**](ApiSetProductApi.md#register_product) | **POST** /product/new | Register a product + + + +## associate_barcode + +> associate_barcode(id, barcode) +Associate a barcode with a product + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**id** | **uuid::Uuid** | The id of the product to associated the barcode with | [required] | +**barcode** | [**Barcode**](Barcode.md) | | [required] | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + + +## register_product + +> uuid::Uuid register_product(product_stub) +Register a product + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**product_stub** | [**ProductStub**](ProductStub.md) | | [required] | + +### Return type + +[**uuid::Uuid**](uuid::Uuid.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/crates/rocie-client/docs/ApiSetUnitApi.md b/crates/rocie-client/docs/ApiSetUnitApi.md new file mode 100644 index 0000000..6d6d397 --- /dev/null +++ b/crates/rocie-client/docs/ApiSetUnitApi.md @@ -0,0 +1,37 @@ +# \ApiSetUnitApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**register_unit**](ApiSetUnitApi.md#register_unit) | **POST** /unit/new | Register an Unit + + + +## register_unit + +> uuid::Uuid register_unit(unit_stub) +Register an Unit + +### Parameters + + +Name | Type | Description | Required | Notes +------------- | ------------- | ------------- | ------------- | ------------- +**unit_stub** | [**UnitStub**](UnitStub.md) | | [required] | + +### Return type + +[**uuid::Uuid**](uuid::Uuid.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json, text/plain + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/crates/rocie-client/docs/Barcode.md b/crates/rocie-client/docs/Barcode.md index 7e6f4fb..d9734fa 100644 --- a/crates/rocie-client/docs/Barcode.md +++ b/crates/rocie-client/docs/Barcode.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **amount** | [**models::UnitAmount**](UnitAmount.md) | | -**id** | **i32** | | +**id** | **i64** | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/crates/rocie-client/docs/Unit.md b/crates/rocie-client/docs/Unit.md new file mode 100644 index 0000000..9fb95a5 --- /dev/null +++ b/crates/rocie-client/docs/Unit.md @@ -0,0 +1,15 @@ +# Unit + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**description** | Option<**String**> | | [optional] +**full_name_plural** | **String** | | +**full_name_singular** | **String** | | +**id** | [**uuid::Uuid**](uuid::Uuid.md) | | +**short_name** | **String** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/crates/rocie-client/docs/UnitAmount.md b/crates/rocie-client/docs/UnitAmount.md index 39b2264..f0c1b5f 100644 --- a/crates/rocie-client/docs/UnitAmount.md +++ b/crates/rocie-client/docs/UnitAmount.md @@ -4,8 +4,8 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**unit** | **String** | | -**value** | **i32** | | +**unit** | [**uuid::Uuid**](uuid::Uuid.md) | | +**value** | **i64** | | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/crates/rocie-client/docs/UnitStub.md b/crates/rocie-client/docs/UnitStub.md new file mode 100644 index 0000000..62ab220 --- /dev/null +++ b/crates/rocie-client/docs/UnitStub.md @@ -0,0 +1,14 @@ +# UnitStub + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**description** | Option<**String**> | | [optional] +**full_name_plural** | **String** | | +**full_name_singular** | **String** | | +**short_name** | **String** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/crates/rocie-client/src/apis/api_get_api.rs b/crates/rocie-client/src/apis/api_get_api.rs index 3217717..a8f4c17 100644 --- a/crates/rocie-client/src/apis/api_get_api.rs +++ b/crates/rocie-client/src/apis/api_get_api.rs @@ -20,6 +20,7 @@ use super::{Error, configuration, ContentType}; #[serde(untagged)] pub enum ProductByIdError { Status404(), + Status500(String), UnknownValue(serde_json::Value), } @@ -27,6 +28,7 @@ pub enum ProductByIdError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum ProductsError { + Status500(String), UnknownValue(serde_json::Value), } diff --git a/crates/rocie-client/src/apis/api_get_product_api.rs b/crates/rocie-client/src/apis/api_get_product_api.rs new file mode 100644 index 0000000..a8f4c17 --- /dev/null +++ b/crates/rocie-client/src/apis/api_get_product_api.rs @@ -0,0 +1,105 @@ +/* + * 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(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`products`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ProductsError { + Status500(String), + 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<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<ProductsError> = 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 new file mode 100644 index 0000000..5895652 --- /dev/null +++ b/crates/rocie-client/src/apis/api_get_unit_api.rs @@ -0,0 +1,105 @@ +/* + * 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 [`unit_by_id`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UnitByIdError { + Status404(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`units`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum UnitsError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn unit_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::Unit, Error<UnitByIdError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_id = id; + + let uri_str = format!("{}/unit/{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::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 `models::Unit`")))), + } + } else { + let content = resp.text().await?; + let entity: Option<UnitByIdError> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) + } +} + +pub async fn units(configuration: &configuration::Configuration, ) -> Result<Vec<models::Unit>, Error<UnitsError>> { + + let uri_str = format!("{}/units/", 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::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<UnitsError> = 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 index 7c0c414..81f029e 100644 --- a/crates/rocie-client/src/apis/api_set_api.rs +++ b/crates/rocie-client/src/apis/api_set_api.rs @@ -19,6 +19,9 @@ use super::{Error, configuration, ContentType}; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AssociateBarcodeError { + Status403(), + Status404(), + Status500(String), UnknownValue(serde_json::Value), } @@ -26,6 +29,7 @@ pub enum AssociateBarcodeError { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum RegisterProductError { + Status500(String), UnknownValue(serde_json::Value), } diff --git a/crates/rocie-client/src/apis/api_set_product_api.rs b/crates/rocie-client/src/apis/api_set_product_api.rs new file mode 100644 index 0000000..0d2679b --- /dev/null +++ b/crates/rocie-client/src/apis/api_set_product_api.rs @@ -0,0 +1,100 @@ +/* + * 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 { + Status403(String), + Status404(), + Status500(String), + UnknownValue(serde_json::Value), +} + +/// struct for typed errors of method [`register_product`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RegisterProductError { + Status500(String), + 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/api_set_unit_api.rs b/crates/rocie-client/src/apis/api_set_unit_api.rs new file mode 100644 index 0000000..e894fc3 --- /dev/null +++ b/crates/rocie-client/src/apis/api_set_unit_api.rs @@ -0,0 +1,63 @@ +/* + * 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 [`register_unit`] +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum RegisterUnitError { + Status500(String), + UnknownValue(serde_json::Value), +} + + +pub async fn register_unit(configuration: &configuration::Configuration, unit_stub: models::UnitStub) -> Result<uuid::Uuid, Error<RegisterUnitError>> { + // add a prefix to parameters to efficiently prevent name collisions + let p_unit_stub = unit_stub; + + let uri_str = format!("{}/unit/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_unit_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<RegisterUnitError> = 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 c3f990f..7daca17 100644 --- a/crates/rocie-client/src/apis/mod.rs +++ b/crates/rocie-client/src/apis/mod.rs @@ -111,7 +111,9 @@ impl From<&str> for ContentType { } } -pub mod api_get_api; -pub mod api_set_api; +pub mod api_get_product_api; +pub mod api_get_unit_api; +pub mod api_set_product_api; +pub mod api_set_unit_api; pub mod configuration; diff --git a/crates/rocie-client/src/models/barcode.rs b/crates/rocie-client/src/models/barcode.rs index 7690be2..2b1759a 100644 --- a/crates/rocie-client/src/models/barcode.rs +++ b/crates/rocie-client/src/models/barcode.rs @@ -16,11 +16,11 @@ pub struct Barcode { #[serde(rename = "amount")] pub amount: Box<models::UnitAmount>, #[serde(rename = "id")] - pub id: i32, + pub id: i64, } impl Barcode { - pub fn new(amount: models::UnitAmount, id: i32) -> Barcode { + pub fn new(amount: models::UnitAmount, id: i64) -> 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 index 6c96c01..42fecc5 100644 --- a/crates/rocie-client/src/models/mod.rs +++ b/crates/rocie-client/src/models/mod.rs @@ -4,5 +4,9 @@ pub mod product; pub use self::product::Product; pub mod product_stub; pub use self::product_stub::ProductStub; +pub mod unit; +pub use self::unit::Unit; pub mod unit_amount; pub use self::unit_amount::UnitAmount; +pub mod unit_stub; +pub use self::unit_stub::UnitStub; diff --git a/crates/rocie-client/src/models/unit.rs b/crates/rocie-client/src/models/unit.rs new file mode 100644 index 0000000..95ec588 --- /dev/null +++ b/crates/rocie-client/src/models/unit.rs @@ -0,0 +1,39 @@ +/* + * 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 Unit { + #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub description: Option<Option<String>>, + #[serde(rename = "full_name_plural")] + pub full_name_plural: String, + #[serde(rename = "full_name_singular")] + pub full_name_singular: String, + #[serde(rename = "id")] + pub id: uuid::Uuid, + #[serde(rename = "short_name")] + pub short_name: String, +} + +impl Unit { + pub fn new(full_name_plural: String, full_name_singular: String, id: uuid::Uuid, short_name: String) -> Unit { + Unit { + description: None, + full_name_plural, + full_name_singular, + id, + short_name, + } + } +} + diff --git a/crates/rocie-client/src/models/unit_amount.rs b/crates/rocie-client/src/models/unit_amount.rs index 038adb0..3ab482c 100644 --- a/crates/rocie-client/src/models/unit_amount.rs +++ b/crates/rocie-client/src/models/unit_amount.rs @@ -14,13 +14,13 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] pub struct UnitAmount { #[serde(rename = "unit")] - pub unit: String, + pub unit: uuid::Uuid, #[serde(rename = "value")] - pub value: i32, + pub value: i64, } impl UnitAmount { - pub fn new(unit: String, value: i32) -> UnitAmount { + pub fn new(unit: uuid::Uuid, value: i64) -> UnitAmount { UnitAmount { unit, value, diff --git a/crates/rocie-client/src/models/unit_stub.rs b/crates/rocie-client/src/models/unit_stub.rs new file mode 100644 index 0000000..03f81fd --- /dev/null +++ b/crates/rocie-client/src/models/unit_stub.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 UnitStub { + #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")] + pub description: Option<Option<String>>, + #[serde(rename = "full_name_plural")] + pub full_name_plural: String, + #[serde(rename = "full_name_singular")] + pub full_name_singular: String, + #[serde(rename = "short_name")] + pub short_name: String, +} + +impl UnitStub { + pub fn new(full_name_plural: String, full_name_singular: String, short_name: String) -> UnitStub { + UnitStub { + description: None, + full_name_plural, + full_name_singular, + short_name, + } + } +} + |
