From c91dce4f77ae12453203f0a28b91efb6533cc095 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 9 Dec 2025 13:07:14 +0100 Subject: feat(rocie-server): Implement basic user handling and authentication --- crates/rocie-server/src/api/set/auth/recipe.rs | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 crates/rocie-server/src/api/set/auth/recipe.rs (limited to 'crates/rocie-server/src/api/set/auth/recipe.rs') diff --git a/crates/rocie-server/src/api/set/auth/recipe.rs b/crates/rocie-server/src/api/set/auth/recipe.rs new file mode 100644 index 0000000..43a034e --- /dev/null +++ b/crates/rocie-server/src/api/set/auth/recipe.rs @@ -0,0 +1,60 @@ +use std::path::PathBuf; + +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}, + }, +}; + +#[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 = 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(stub.path, stub.content, &mut ops); + + ops.apply(&app).await?; + + Ok(HttpResponse::Ok().json(recipe.id)) +} -- cgit 1.4.1