diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-06 10:31:40 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-09-06 10:31:40 +0200 |
| commit | 9a9d5c5880095adeb43a045dca638243c8f946e4 (patch) | |
| tree | 86e0d23af339b3139efab15749aaf5b59aa0965b /crates/rocie-client | |
| parent | chore: Initial commit (diff) | |
| download | server-9a9d5c5880095adeb43a045dca638243c8f946e4.zip | |
feat: Provide basic API frame
Diffstat (limited to 'crates/rocie-client')
30 files changed, 983 insertions, 0 deletions
diff --git a/crates/rocie-client/.gitignore b/crates/rocie-client/.gitignore new file mode 100644 index 0000000..6aa1064 --- /dev/null +++ b/crates/rocie-client/.gitignore @@ -0,0 +1,3 @@ +/target/ +**/*.rs.bk +Cargo.lock diff --git a/crates/rocie-client/.openapi-generator-ignore b/crates/rocie-client/.openapi-generator-ignore new file mode 100644 index 0000000..b0147e0 --- /dev/null +++ b/crates/rocie-client/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +Cargo.toml + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/crates/rocie-client/.openapi-generator/FILES b/crates/rocie-client/.openapi-generator/FILES new file mode 100644 index 0000000..f9b70e6 --- /dev/null +++ b/crates/rocie-client/.openapi-generator/FILES @@ -0,0 +1,20 @@ +.gitignore +.travis.yml +README.md +docs/ApiGetApi.md +docs/ApiSetApi.md +docs/Barcode.md +docs/Product.md +docs/ProductStub.md +docs/UnitAmount.md +git_push.sh +src/apis/api_get_api.rs +src/apis/api_set_api.rs +src/apis/configuration.rs +src/apis/mod.rs +src/lib.rs +src/models/barcode.rs +src/models/mod.rs +src/models/product.rs +src/models/product_stub.rs +src/models/unit_amount.rs diff --git a/crates/rocie-client/.openapi-generator/VERSION b/crates/rocie-client/.openapi-generator/VERSION new file mode 100644 index 0000000..e465da4 --- /dev/null +++ b/crates/rocie-client/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.14.0 diff --git a/crates/rocie-client/.travis.yml b/crates/rocie-client/.travis.yml new file mode 100644 index 0000000..22761ba --- /dev/null +++ b/crates/rocie-client/.travis.yml @@ -0,0 +1 @@ +language: rust diff --git a/crates/rocie-client/Cargo.toml b/crates/rocie-client/Cargo.toml new file mode 100644 index 0000000..96e0e24 --- /dev/null +++ b/crates/rocie-client/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rocie-client" +version = "0.1.0" +authors = ["benedikt.peetz@b-peetz.de"] +description = "An enterprise grocery management system" +license = "GPL-3.0-or-later" +edition = "2024" + +[dependencies] +serde = { version = "^1.0", features = ["derive"] } +serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] } +serde_json = "^1.0" +serde_repr = "^0.1" +url = "^2.5" +uuid = { version = "^1.8", features = ["serde", "v4"] } +reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] } diff --git a/crates/rocie-client/README.md b/crates/rocie-client/README.md new file mode 100644 index 0000000..7649325 --- /dev/null +++ b/crates/rocie-client/README.md @@ -0,0 +1,52 @@ +# Rust API client for openapi + +An enterprise grocery management system + + +## Overview + +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client. + +- API version: 0.1.0 +- Package version: 0.1.0 +- Generator version: 7.14.0 +- Build package: `org.openapitools.codegen.languages.RustClientCodegen` + +## Installation + +Put the package under your project folder in a directory named `openapi` and add the following to `Cargo.toml` under `[dependencies]`: + +``` +openapi = { path = "./openapi" } +``` + +## Documentation for API Endpoints + +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 + + +## Documentation For Models + + - [Barcode](docs/Barcode.md) + - [Product](docs/Product.md) + - [ProductStub](docs/ProductStub.md) + - [UnitAmount](docs/UnitAmount.md) + + +To get access to the crate's generated documentation, use: + +``` +cargo doc --open +``` + +## Author + +benedikt.peetz@b-peetz.de + diff --git a/crates/rocie-client/docs/ApiGetApi.md b/crates/rocie-client/docs/ApiGetApi.md new file mode 100644 index 0000000..f2df94c --- /dev/null +++ b/crates/rocie-client/docs/ApiGetApi.md @@ -0,0 +1,63 @@ +# \ApiGetApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**product_by_id**](ApiGetApi.md#product_by_id) | **GET** /product/{id} | Get Product by id +[**products**](ApiGetApi.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 + +[[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 + +[[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 new file mode 100644 index 0000000..87f88b8 --- /dev/null +++ b/crates/rocie-client/docs/ApiSetApi.md @@ -0,0 +1,67 @@ +# \ApiSetApi + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**associate_barcode**](ApiSetApi.md#associate_barcode) | **POST** /product/{id}/associate | Associate a barcode with a product +[**register_product**](ApiSetApi.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**: Not defined + +[[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 + +[[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 new file mode 100644 index 0000000..8c58cb3 --- /dev/null +++ b/crates/rocie-client/docs/BarCode.md @@ -0,0 +1,11 @@ +# BarCode + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**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/Barcode.md b/crates/rocie-client/docs/Barcode.md new file mode 100644 index 0000000..7e6f4fb --- /dev/null +++ b/crates/rocie-client/docs/Barcode.md @@ -0,0 +1,12 @@ +# Barcode + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**amount** | [**models::UnitAmount**](UnitAmount.md) | | +**id** | **i32** | | + +[[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/Product.md b/crates/rocie-client/docs/Product.md new file mode 100644 index 0000000..3995429 --- /dev/null +++ b/crates/rocie-client/docs/Product.md @@ -0,0 +1,14 @@ +# Product + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**associated_bar_codes** | [**Vec<models::Barcode>**](Barcode.md) | | +**description** | Option<**String**> | | [optional] +**id** | [**uuid::Uuid**](uuid::Uuid.md) | | +**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/ProductOneOf.md b/crates/rocie-client/docs/ProductOneOf.md new file mode 100644 index 0000000..1ab44aa --- /dev/null +++ b/crates/rocie-client/docs/ProductOneOf.md @@ -0,0 +1,11 @@ +# ProductOneOf + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**mass** | **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/ProductOneOf1.md b/crates/rocie-client/docs/ProductOneOf1.md new file mode 100644 index 0000000..f395a25 --- /dev/null +++ b/crates/rocie-client/docs/ProductOneOf1.md @@ -0,0 +1,11 @@ +# ProductOneOf1 + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**volume** | **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/ProductStub.md b/crates/rocie-client/docs/ProductStub.md new file mode 100644 index 0000000..d0b0db8 --- /dev/null +++ b/crates/rocie-client/docs/ProductStub.md @@ -0,0 +1,13 @@ +# ProductStub + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**description** | Option<**String**> | | [optional] +**name** | **String** | | +**parent** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [optional] + +[[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 new file mode 100644 index 0000000..39b2264 --- /dev/null +++ b/crates/rocie-client/docs/UnitAmount.md @@ -0,0 +1,12 @@ +# UnitAmount + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**unit** | **String** | | +**value** | **i32** | | + +[[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/git_push.sh b/crates/rocie-client/git_push.sh new file mode 100644 index 0000000..f53a75d --- /dev/null +++ b/crates/rocie-client/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' 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<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_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, + } + } +} + |
