diff --git a/README.md b/README.md index 2c17810..a4ce94f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ To set up the database locally, you'll need Docker installed. Follow the steps b 2. **Run the Docker Container**: ```bash - docker run -d -p 3306:3306 --name Smart-Cooking_Database -e MYSQL_ROOT_PASSWORD=myrootpassword smartcooking-mariadb + docker run -d -p 3306:3306 --name Smart-Cooking_Database -e MARIADB_ROOT_PASSWORD=myrootpassword smartcooking-mariadb ``` 3. **Access the Database**: diff --git a/database.sql b/database.sql index 1da26b7..0d2e65f 100644 --- a/database.sql +++ b/database.sql @@ -97,8 +97,11 @@ CREATE OR REPLACE TABLE recipe ( publication_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, modification_date TIMESTAMP NULL, picture_id INT NULL, + preparation_time INT UNSIGNED NULL, cook_time INT UNSIGNED NULL, + servings INT UNSIGNED NULL, difficulty_level TINYINT CHECK (difficulty_level BETWEEN 1 AND 3), + estimated_cost TINYINT CHECK (estimated_cost BETWEEN 1 AND 3), number_of_reviews INT NULL, recipe_source VARCHAR(255) NULL, recipe_status TINYINT NOT NULL DEFAULT 1, diff --git a/procedures/get/recipe.sql b/procedures/get/recipe.sql index 6a9e378..920137a 100644 --- a/procedures/get/recipe.sql +++ b/procedures/get/recipe.sql @@ -9,15 +9,20 @@ CREATE OR REPLACE PROCEDURE get_recipe_by_id( ) BEGIN SELECT + r.recipe_id, r.author_id, p.person_name AS author_name, r.publication_date, r.modification_date, r.picture_id, + r.preparation_time, r.cook_time, + r.servings, r.difficulty_level, + r.estimated_cost, r.number_of_reviews, - r.recipe_status, + r.recipe_source, + rs.status_name AS recipe_status, rt.title, rt.details, rt.preparation, @@ -27,6 +32,7 @@ BEGIN INNER JOIN recipe_translation rt ON r.recipe_id = rt.recipe_id INNER JOIN lang l ON rt.language_id = l.language_id INNER JOIN person p ON r.author_id = p.person_id + INNER JOIN recipe_status rs ON r.recipe_status = rs.status_id WHERE r.recipe_id = p_recipe_id AND l.iso_code = p_language_iso_code; END // @@ -107,7 +113,7 @@ CREATE OR REPLACE PROCEDURE get_recipes_by_author_paginated( ) BEGIN CALL get_recipes_paginated( - 'AND r.author_id = ?', p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, NULL + 'AND r.author_id = ?', p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, p_author_id ); END // @@ -150,7 +156,7 @@ CREATE OR REPLACE PROCEDURE get_recipes_by_category_paginated( BEGIN CALL get_recipes_paginated( 'INNER JOIN recipe_category rc ON r.recipe_id = rc.recipe_id AND rc.category_id = ?', - p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, NULL + p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, p_category_id ); END // @@ -163,9 +169,8 @@ CREATE OR REPLACE PROCEDURE get_recipes_by_tags_paginated( ) BEGIN CALL get_recipes_paginated( - 'INNER JOIN recipe_tag rtg ON r.recipe_id = rtg.recipe_id ' - 'AND JSON_CONTAINS(?, JSON_QUOTE(rtg.tag))', - p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, NULL + 'INNER JOIN recipe_tag rtg ON r.recipe_id = rtg.recipe_id AND JSON_CONTAINS(?, JSON_QUOTE(rtg.tag))', + p_limit, p_offset, p_language_iso_code, NULL, NULL, NULL, p_tags ); END // diff --git a/procedures/insert/recipe.sql b/procedures/insert/recipe.sql index 4236fb5..0179171 100644 --- a/procedures/insert/recipe.sql +++ b/procedures/insert/recipe.sql @@ -3,28 +3,58 @@ USE smartcooking; DELIMITER // -CREATE OR REPLACE PROCEDURE insert_recipe( - IN author_id INT, - IN picture_id INT, - IN cook_time INT, - IN difficulty_level TINYINT, - IN recipe_source VARCHAR(255), - IN recipe_status_name VARCHAR(25) +CREATE OR REPLACE PROCEDURE insert_recipe ( + IN p_author_id INT, + IN p_picture_id INT, + IN p_preparation_time INT, + IN p_cook_time INT, + IN p_servings INT, + IN p_difficulty_level TINYINT, + IN p_estimated_cost TINYINT, + IN p_number_of_reviews INT, + IN p_recipe_source VARCHAR(255), + IN p_recipe_status_name VARCHAR(25) ) BEGIN - DECLARE status_id TINYINT; + DECLARE v_status_id TINYINT DEFAULT NULL; - SELECT status_id INTO status_id + -- Retrieve the status_id corresponding to the status name + SELECT status_id + INTO v_status_id FROM recipe_status - WHERE status_name = recipe_status_name; + WHERE status_name = p_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; + -- Default to 'draft' (status_id = 1) if the status name is not found + IF v_status_id IS NULL THEN + SET v_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, status_id); + -- Insert a new recipe + INSERT INTO recipe ( + author_id, + picture_id, + preparation_time, + cook_time, + servings, + difficulty_level, + estimated_cost, + number_of_reviews, + recipe_source, + recipe_status, + modification_date + ) VALUES ( + p_author_id, + p_picture_id, + p_preparation_time, + p_cook_time, + p_servings, + p_difficulty_level, + p_estimated_cost, + p_number_of_reviews, + p_recipe_source, + v_status_id, + CURRENT_TIMESTAMP + ); END // DELIMITER ;