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)) }