From 95f1407ae78302395c1a3d6fb394d74271fdcfd8 Mon Sep 17 00:00:00 2001
From: Gwendal Margely <gwendal.margely.etu@univ-lille.fr>
Date: Fri, 15 Mar 2024 21:55:03 +0100
Subject: [PATCH] ajout doc et modif IngredientDAO.java

---
 Documentation/documentation.md     | 27 +++++++++++++++++++++++++++
 WEB-INF/src/DAO/IngredientDAO.java |  9 +++++----
 2 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/documentation.md

diff --git a/Documentation/documentation.md b/Documentation/documentation.md
new file mode 100644
index 0000000..ce410cc
--- /dev/null
+++ b/Documentation/documentation.md
@@ -0,0 +1,27 @@
+# Documentation pour les tables et les requetes
+
+## Table Ingrédients
+
+### Création de la table
+
+```sql
+/*au cas ou l'on voudrait être un terroriste et enlever la table si elle existe déja  DROP TABLE IF EXISTS ingredients CASCADE;*/
+CREATE TABLE ingredients(id INT PRIMARY KEY, nom TEXT UNIQUE, price REAL);
+INSERT INTO TABLE ingredients(id,nom ,price) VALUES (1,'jambon',2.00),(2,'poivrons',3.00),(3,'mozarella',2.50),(4,'lardons',2.20),(5,'miel',3.50),(6,'chorizo',4.00);
+```
+
+### Requête sur la table
+
+FIND ALL
+```sql
+SELECT nom ,price FROM ingredients;
+```
+
+Sélectionner seulement un ingrédient \
+les ? représentent l'élément passé en argument 
+
+```sql
+SELECT nom , price , FROM ingrédient where id = ?;
+```
+
+
diff --git a/WEB-INF/src/DAO/IngredientDAO.java b/WEB-INF/src/DAO/IngredientDAO.java
index ba48122..5eec7f8 100644
--- a/WEB-INF/src/DAO/IngredientDAO.java
+++ b/WEB-INF/src/DAO/IngredientDAO.java
@@ -1,4 +1,5 @@
 package DAO;
+
 import Exceptions.IngredientDAOException;
 import POJO.Ingredient;
 
@@ -19,8 +20,8 @@ public class IngredientDAO {
 
     // SQL queries
     private static final String SELECT_ALL_QUERY = "SELECT * FROM ingredients";
-    private static final String INSERT_QUERY = "INSERT INTO ingredients(name, price) VALUES (?, ?)";
-    private static final String SELECT_BY_ID_QUERY = "SELECT * FROM ingredients WHERE id = ?";
+    private static final String INSERT_QUERY = "INSERT INTO ingredients(nom, price) VALUES (?, ?)";
+    private static final String SELECT_BY_ID_QUERY = "SELECT nom,price FROM ingredients WHERE id = ?";
     private static final String DELETE_QUERY = "DELETE FROM ingredients WHERE id = ?";
 
     // Method to establish database connection
@@ -60,7 +61,7 @@ public class IngredientDAO {
 
             while (resultSet.next()) {
                 int id = resultSet.getInt("id");
-                String name = resultSet.getString("name");
+                String name = resultSet.getString("nom");
                 double price = resultSet.getDouble("price");
                 Ingredient ingredient = new Ingredient(id, name, price);
                 ingredients.add(ingredient);
@@ -99,7 +100,7 @@ public class IngredientDAO {
             resultSet = preparedStatement.executeQuery();
 
             if (resultSet.next()) {
-                String name = resultSet.getString("name");
+                String name = resultSet.getString("nom");
                 double price = resultSet.getDouble("price");
                 ingredient = new Ingredient(id, name, price);
             }
-- 
GitLab