diff --git a/procedures/insert/recipe.sql b/procedures/insert/recipe.sql index a76bfcc..4236fb5 100644 --- a/procedures/insert/recipe.sql +++ b/procedures/insert/recipe.sql @@ -9,15 +9,22 @@ CREATE OR REPLACE PROCEDURE insert_recipe( IN cook_time INT, IN difficulty_level TINYINT, IN recipe_source VARCHAR(255), - IN recipe_status VARCHAR(20) + IN recipe_status_name VARCHAR(25) ) BEGIN - IF recipe_status IS NULL THEN - SET recipe_status = 'pending review'; + DECLARE status_id TINYINT; + + SELECT status_id INTO status_id + FROM recipe_status + WHERE status_name = recipe_status_name; + + -- If the status name is not found, default to 'draft' (status_id = 1) + IF status_id IS NULL THEN + SET status_id = 1; END IF; INSERT INTO recipe (author_id, picture_id, cook_time, difficulty_level, recipe_source, recipe_status) - VALUES (author_id, picture_id, cook_time, difficulty_level, recipe_source, recipe_status); + VALUES (author_id, picture_id, cook_time, difficulty_level, recipe_source, status_id); END // DELIMITER ;