From 567001bdc6967b98b6dd3c38ebf45dcba7f247cf Mon Sep 17 00:00:00 2001 From: Vianney Veremme Date: Fri, 18 Apr 2025 18:27:46 -0400 Subject: [PATCH] Add procedure to retrieve recipes by status with pagination --- procedures/get/recipe.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/procedures/get/recipe.sql b/procedures/get/recipe.sql index 920137a..ede5d18 100644 --- a/procedures/get/recipe.sql +++ b/procedures/get/recipe.sql @@ -192,4 +192,26 @@ BEGIN ); END // +-- Procedure for retrieving recipes by status with pagination +CREATE OR REPLACE PROCEDURE get_recipes_by_status_paginated( + IN p_status_name INT, + IN p_limit INT, + IN p_offset INT, + IN p_language_iso_code CHAR(2) +) +BEGIN + DECLARE v_status_id INT; + SELECT status_id INTO v_status_id + FROM recipe_status + WHERE status_name = p_status_name; + IF v_status_id IS NULL THEN + v_status_id = 1; -- Default to 'draft' (status_id = 1) if the status name is not found + END IF; + + CALL get_recipes_paginated( + 'AND r.recipe_status = ?', + p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, v_status_id + ); +END // + DELIMITER ;