From a62ab5c6dacaddb67931d7ac160bc7faaa707737 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 28 Nov 2025 16:30:02 +0100 Subject: feat(crates/rocie-server): Get closer to feature parity between rocie and grocy --- crates/rocie-server/src/api/set/recipe.rs | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 crates/rocie-server/src/api/set/recipe.rs (limited to 'crates/rocie-server/src/api/set/recipe.rs') 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, + stub: web::Json, +) -> Result { + 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)) +} -- cgit 1.4.1