aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/src/api/set
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
commita62ab5c6dacaddb67931d7ac160bc7faaa707737 (patch)
treea35fa3540fbb89f575ab1ea72f9b23ace399e01c /crates/rocie-server/src/api/set
parentchore(crates/rocie-client): Re-generate (diff)
downloadserver-a62ab5c6dacaddb67931d7ac160bc7faaa707737.zip
feat(crates/rocie-server): Get closer to feature parity between rocie and grocy
Diffstat (limited to 'crates/rocie-server/src/api/set')
-rw-r--r--crates/rocie-server/src/api/set/mod.rs4
-rw-r--r--crates/rocie-server/src/api/set/product.rs7
-rw-r--r--crates/rocie-server/src/api/set/product_parent.rs60
-rw-r--r--crates/rocie-server/src/api/set/recipe.rs54
-rw-r--r--crates/rocie-server/src/api/set/unit.rs2
-rw-r--r--crates/rocie-server/src/api/set/unit_property.rs4
6 files changed, 129 insertions, 2 deletions
diff --git a/crates/rocie-server/src/api/set/mod.rs b/crates/rocie-server/src/api/set/mod.rs
index 5dd0219..a6037b9 100644
--- a/crates/rocie-server/src/api/set/mod.rs
+++ b/crates/rocie-server/src/api/set/mod.rs
@@ -2,12 +2,16 @@ use actix_web::web;
pub(crate) mod barcode;
pub(crate) mod product;
+pub(crate) mod product_parent;
+pub(crate) mod recipe;
pub(crate) mod unit;
pub(crate) mod unit_property;
pub(crate) fn register_paths(cfg: &mut web::ServiceConfig) {
cfg.service(product::register_product)
.service(product::associate_barcode)
+ .service(product_parent::register_product_parent)
+ .service(recipe::add_recipe)
.service(unit::register_unit)
.service(unit_property::register_unit_property)
.service(barcode::consume_barcode)
diff --git a/crates/rocie-server/src/api/set/product.rs b/crates/rocie-server/src/api/set/product.rs
index 7372d23..74a92d2 100644
--- a/crates/rocie-server/src/api/set/product.rs
+++ b/crates/rocie-server/src/api/set/product.rs
@@ -8,6 +8,7 @@ use crate::{
barcode::Barcode,
insert::Operations,
product::{Product, ProductId, ProductIdStub},
+ product_parent::ProductParentId,
unit::Unit,
unit_property::UnitPropertyId,
},
@@ -22,10 +23,12 @@ struct ProductStub {
unit_property: UnitPropertyId,
/// A description.
+ #[schema(nullable = false)]
description: Option<String>,
/// A parent of this product, otherwise the parent will be the root of the parent tree.
- parent: Option<ProductId>,
+ #[schema(nullable = false)]
+ parent: Option<ProductParentId>,
}
/// Register a product
@@ -54,7 +57,7 @@ pub(crate) async fn register_product(
let product = Product::register(
product_stub.name.clone(),
product_stub.description.clone(),
- product_stub.parent,
+ product_stub.parent.into(),
product_stub.unit_property,
&mut ops,
);
diff --git a/crates/rocie-server/src/api/set/product_parent.rs b/crates/rocie-server/src/api/set/product_parent.rs
new file mode 100644
index 0000000..f917207
--- /dev/null
+++ b/crates/rocie-server/src/api/set/product_parent.rs
@@ -0,0 +1,60 @@
+use actix_web::{HttpResponse, Responder, Result, post, web};
+use serde::Deserialize;
+use utoipa::ToSchema;
+
+use crate::{
+ app::App,
+ storage::sql::{
+ insert::Operations,
+ product_parent::{ProductParent, ProductParentId},
+ },
+};
+
+#[derive(Deserialize, ToSchema)]
+struct ProductParentStub {
+ /// The name of the product parent
+ name: String,
+
+ /// A description.
+ #[schema(nullable = false)]
+ description: Option<String>,
+
+ /// A parent of this product parent, otherwise the parent will be the root of the parent tree.
+ #[schema(nullable = false)]
+ parent: Option<ProductParentId>,
+}
+
+/// Register a product parent
+#[utoipa::path(
+ responses(
+ (
+ status = 200,
+ description = "Product parent successfully registered in database",
+ body = ProductParentId,
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String,
+ )
+ ),
+ request_body = ProductParentStub,
+)]
+#[post("/product_parent/new")]
+pub(crate) async fn register_product_parent(
+ app: web::Data<App>,
+ product_stub: web::Json<ProductParentStub>,
+) -> Result<impl Responder> {
+ let mut ops = Operations::new("register product parent");
+
+ let product = ProductParent::register(
+ product_stub.name.clone(),
+ product_stub.description.clone(),
+ product_stub.parent.into(),
+ &mut ops,
+ );
+
+ ops.apply(&app).await?;
+
+ Ok(HttpResponse::Ok().json(product.id))
+}
diff --git a/crates/rocie-server/src/api/set/recipe.rs b/crates/rocie-server/src/api/set/recipe.rs
new file mode 100644
index 0000000..bb5be37
--- /dev/null
+++ b/crates/rocie-server/src/api/set/recipe.rs
@@ -0,0 +1,54 @@
+use std::path::PathBuf;
+
+use actix_web::{HttpResponse, Responder, error::Result, post, web};
+use serde::Deserialize;
+use utoipa::ToSchema;
+
+use crate::{
+ app::App,
+ storage::sql::{
+ insert::Operations,
+ recipe::{Recipe, RecipeId},
+ },
+};
+
+#[derive(Deserialize, ToSchema)]
+struct RecipeStub {
+ /// The path the recipe should have
+ #[schema(value_type = String)]
+ path: PathBuf,
+
+ /// The content of this recipe, in cooklang format
+ content: String,
+}
+
+/// Register a product parent
+#[utoipa::path(
+ responses(
+ (
+ status = 200,
+ description = "Product parent successfully registered in database",
+ body = RecipeId,
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String,
+ )
+ ),
+ request_body = RecipeStub,
+)]
+#[post("/recipe/new")]
+pub(crate) async fn add_recipe(
+ app: web::Data<App>,
+ stub: web::Json<RecipeStub>,
+) -> Result<impl Responder> {
+ let stub = stub.into_inner();
+ let mut ops = Operations::new("add recipe parent");
+
+ let recipe = Recipe::new(stub.path, stub.content, &mut ops);
+
+ ops.apply(&app).await?;
+
+ Ok(HttpResponse::Ok().json(recipe.id))
+}
diff --git a/crates/rocie-server/src/api/set/unit.rs b/crates/rocie-server/src/api/set/unit.rs
index 5f39c8f..1671918 100644
--- a/crates/rocie-server/src/api/set/unit.rs
+++ b/crates/rocie-server/src/api/set/unit.rs
@@ -17,6 +17,8 @@ struct UnitStub {
full_name_singular: String,
short_name: String,
unit_property: UnitPropertyId,
+
+ #[schema(nullable = false)]
description: Option<String>,
}
diff --git a/crates/rocie-server/src/api/set/unit_property.rs b/crates/rocie-server/src/api/set/unit_property.rs
index 9915e84..ca2960f 100644
--- a/crates/rocie-server/src/api/set/unit_property.rs
+++ b/crates/rocie-server/src/api/set/unit_property.rs
@@ -12,7 +12,11 @@ use crate::{
#[derive(Deserialize, ToSchema)]
struct UnitPropertyStub {
+ /// The name of the unit property.
name: String,
+
+ /// An optional description of the unit property.
+ #[schema(nullable = false)]
description: Option<String>,
}