Skip to content

Commit 099260b

Browse files
authored
Refactor insert_recipe procedure to use status name (#20)
Refactor `insert_recipe` procedure to use status ID instead of status name
1 parent f1e1344 commit 099260b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

procedures/insert/recipe.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@ CREATE OR REPLACE PROCEDURE insert_recipe(
99
IN cook_time INT,
1010
IN difficulty_level TINYINT,
1111
IN recipe_source VARCHAR(255),
12-
IN recipe_status VARCHAR(20)
12+
IN recipe_status_name VARCHAR(25)
1313
)
1414
BEGIN
15-
IF recipe_status IS NULL THEN
16-
SET recipe_status = 'pending review';
15+
DECLARE status_id TINYINT;
16+
17+
SELECT status_id INTO status_id
18+
FROM recipe_status
19+
WHERE status_name = recipe_status_name;
20+
21+
-- If the status name is not found, default to 'draft' (status_id = 1)
22+
IF status_id IS NULL THEN
23+
SET status_id = 1;
1724
END IF;
1825

1926
INSERT INTO recipe (author_id, picture_id, cook_time, difficulty_level, recipe_source, recipe_status)
20-
VALUES (author_id, picture_id, cook_time, difficulty_level, recipe_source, recipe_status);
27+
VALUES (author_id, picture_id, cook_time, difficulty_level, recipe_source, status_id);
2128
END //
2229

2330
DELIMITER ;

0 commit comments

Comments
 (0)