// rocie - An enterprise grocery management system // // Copyright (C) 2026 Benedikt Peetz // SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of Rocie. // // You should have received a copy of the License along with this program. // If not, see . use actix_identity::Identity; 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}, recipe_parent::RecipeParentId, }, }; #[derive(Deserialize, ToSchema)] struct RecipeStub { /// The globally unique name of this recipe name: String, /// The optional parent of this recipe. #[schema(nullable = false)] parent: Option, /// The content of this recipe, in cooklang format content: String, } /// Register a product parent #[utoipa::path( responses( ( status = OK, description = "Product parent successfully registered in database", body = RecipeId, ), ( status = UNAUTHORIZED, description = "You did not login before calling this endpoint", ), ( 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, _user: Identity, ) -> Result { let stub = stub.into_inner(); let mut ops = Operations::new("add recipe parent"); let recipe = Recipe::new(&app, stub.name, stub.parent, stub.content, &mut ops).await?; ops.apply(&app).await?; Ok(HttpResponse::Ok().json(recipe.id)) }