aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/src/api/set/auth
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-server/src/api/set/auth')
-rw-r--r--crates/rocie-server/src/api/set/auth/mod.rs2
-rw-r--r--crates/rocie-server/src/api/set/auth/recipe.rs21
-rw-r--r--crates/rocie-server/src/api/set/auth/recipe_parent.rs67
3 files changed, 84 insertions, 6 deletions
diff --git a/crates/rocie-server/src/api/set/auth/mod.rs b/crates/rocie-server/src/api/set/auth/mod.rs
index 4e733a9..6379f22 100644
--- a/crates/rocie-server/src/api/set/auth/mod.rs
+++ b/crates/rocie-server/src/api/set/auth/mod.rs
@@ -4,6 +4,7 @@ pub(crate) mod barcode;
pub(crate) mod product;
pub(crate) mod product_parent;
pub(crate) mod recipe;
+pub(crate) mod recipe_parent;
pub(crate) mod unit;
pub(crate) mod unit_property;
pub(crate) mod user;
@@ -13,6 +14,7 @@ pub(crate) fn register_paths(cfg: &mut web::ServiceConfig) {
.service(product::associate_barcode)
.service(product_parent::register_product_parent)
.service(recipe::add_recipe)
+ .service(recipe_parent::register_recipe_parent)
.service(unit::register_unit)
.service(unit_property::register_unit_property)
.service(barcode::consume_barcode)
diff --git a/crates/rocie-server/src/api/set/auth/recipe.rs b/crates/rocie-server/src/api/set/auth/recipe.rs
index 43a034e..b9f930d 100644
--- a/crates/rocie-server/src/api/set/auth/recipe.rs
+++ b/crates/rocie-server/src/api/set/auth/recipe.rs
@@ -1,5 +1,3 @@
-use std::path::PathBuf;
-
use actix_identity::Identity;
use actix_web::{HttpResponse, Responder, error::Result, post, web};
use serde::Deserialize;
@@ -10,14 +8,18 @@ use crate::{
storage::sql::{
insert::Operations,
recipe::{Recipe, RecipeId},
+ recipe_parent::RecipeParentId,
},
};
#[derive(Deserialize, ToSchema)]
struct RecipeStub {
- /// The path the recipe should have
- #[schema(value_type = String)]
- path: PathBuf,
+ /// The globally unique name of this recipe
+ name: String,
+
+ /// The optional parent of this recipe.
+ #[schema(nullable = false)]
+ parent: Option<RecipeParentId>,
/// The content of this recipe, in cooklang format
content: String,
@@ -52,7 +54,14 @@ pub(crate) async fn add_recipe(
let stub = stub.into_inner();
let mut ops = Operations::new("add recipe parent");
- let recipe = Recipe::new(stub.path, stub.content, &mut ops);
+ let recipe = Recipe::new(
+ &app,
+ stub.name,
+ stub.parent,
+ stub.content,
+ &mut ops,
+ )
+ .await?;
ops.apply(&app).await?;
diff --git a/crates/rocie-server/src/api/set/auth/recipe_parent.rs b/crates/rocie-server/src/api/set/auth/recipe_parent.rs
new file mode 100644
index 0000000..e020dd3
--- /dev/null
+++ b/crates/rocie-server/src/api/set/auth/recipe_parent.rs
@@ -0,0 +1,67 @@
+use actix_identity::Identity;
+use actix_web::{HttpResponse, Responder, Result, post, web};
+use serde::Deserialize;
+use utoipa::ToSchema;
+
+use crate::{
+ app::App,
+ storage::sql::{
+ insert::Operations,
+ recipe_parent::{RecipeParent, RecipeParentId},
+ },
+};
+
+#[derive(Deserialize, ToSchema)]
+struct RecipeParentStub {
+ /// The name of the recipe parent
+ name: String,
+
+ /// A description.
+ #[schema(nullable = false)]
+ description: Option<String>,
+
+ /// A parent of this recipe parent, otherwise the parent will be the root of the parent tree.
+ #[schema(nullable = false)]
+ parent: Option<RecipeParentId>,
+}
+
+/// Register a product parent
+#[utoipa::path(
+ responses(
+ (
+ status = OK,
+ description = "Recipe parent successfully registered in database",
+ body = RecipeParentId,
+ ),
+ (
+ status = UNAUTHORIZED,
+ description = "You did not login before calling this endpoint",
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String,
+ )
+ ),
+ request_body = RecipeParentStub,
+)]
+#[post("/recipe_parent/new")]
+pub(crate) async fn register_recipe_parent(
+ app: web::Data<App>,
+ parent_stub: web::Json<RecipeParentStub>,
+ _user: Identity,
+) -> Result<impl Responder> {
+ let parent_stub = parent_stub.into_inner();
+ let mut ops = Operations::new("register recipe parent");
+
+ let parent = RecipeParent::register(
+ parent_stub.name,
+ parent_stub.description,
+ parent_stub.parent,
+ &mut ops,
+ );
+
+ ops.apply(&app).await?;
+
+ Ok(HttpResponse::Ok().json(parent.id))
+}