From 21dd405737fffe4a389683f2b9dcc70f35316793 Mon Sep 17 00:00:00 2001
From: Gaydamakha <mikhail.gaydamakha@etu.unistra.fr>
Date: Fri, 19 Nov 2021 12:27:39 +0100
Subject: [PATCH] :recycle: rename ref to id in Item model

---
 scripts/create-dev.sql                             | 12 ++++++------
 .../java/fr/unistra/sil/erp/back/model/Item.java   | 14 +++++++-------
 .../repository/item/SqliteItemsRepository.java     |  6 +++---
 .../repository/stock/SqliteStocksRepository.java   |  2 +-
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/scripts/create-dev.sql b/scripts/create-dev.sql
index f73ce2f..3f57a31 100644
--- a/scripts/create-dev.sql
+++ b/scripts/create-dev.sql
@@ -11,7 +11,7 @@ CREATE TABLE categories (
 );
 
 CREATE TABLE items (
-    ref INTEGER PRIMARY KEY,
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
     name TEXT NOT NULL,
     price REAL NOT NULL,
     subscriberPrice REAL NOT NULL,
@@ -45,17 +45,17 @@ CREATE TABLE stocks (
     id INTEGER PRIMARY KEY,
     item INTEGER NOT NULL,
     quantity INTEGER NOT NULL,
-    FOREIGN KEY (item) REFERENCES items (ref)
+    FOREIGN KEY (item) REFERENCES items (id)
 );
 
 INSERT INTO categories (id, name)
     VALUES (1, "Boissons"),
 	       (2, "Snacks");
 
-INSERT INTO items (ref, name, price, subscriberPrice, category)
-    VALUES (1, "Jus d'orange", 1.00, 0.50, 1),
-           (2, "Coca-Cola",    1.50, 1.00, 1),
-		   (3, "Twix",         1.10, 0.80, 2);
+INSERT INTO items (name, price, subscriberPrice, category)
+    VALUES ("Jus d'orange", 1.00, 0.50, 1),
+           ("Coca-Cola",    1.50, 1.00, 1),
+		   ("Twix",         1.10, 0.80, 2);
 
 INSERT INTO transaction_types (id, name)
     VALUES (1, "ACHAT"),
diff --git a/src/main/java/fr/unistra/sil/erp/back/model/Item.java b/src/main/java/fr/unistra/sil/erp/back/model/Item.java
index a7586d8..c9b4cde 100644
--- a/src/main/java/fr/unistra/sil/erp/back/model/Item.java
+++ b/src/main/java/fr/unistra/sil/erp/back/model/Item.java
@@ -23,7 +23,7 @@ public class Item {
     /**
      * The product's reference number.
      */
-    private final int ref;
+    private final Integer id;
     
     /**
      * The product's name.
@@ -47,16 +47,16 @@ public class Item {
     
     /**
      * Class constructor.
-     * @param ref The item's reference number.
+     * @param id The item's reference number.
      * @param name The item's name.
      * @param price The item's price.
      * @param subscriberPrice The item's price for subscribers.
      * @param category The item's category.
      */
-    public Item(int ref, String name, BigDecimal price,
-            BigDecimal subscriberPrice, int category)
+    public Item(Integer id, String name, BigDecimal price,
+                BigDecimal subscriberPrice, int category)
     {
-        this.ref = ref;
+        this.id = id;
         this.name = name;
         this.price = price;
         this.subscriberPrice = subscriberPrice;
@@ -67,9 +67,9 @@ public class Item {
      * Returns the current item's reference number.
      * @return the reference number.
      */
-    public int getRef()
+    public Integer getId()
     {
-        return this.ref;
+        return this.id;
     }
     
     /**
diff --git a/src/main/java/fr/unistra/sil/erp/back/repository/item/SqliteItemsRepository.java b/src/main/java/fr/unistra/sil/erp/back/repository/item/SqliteItemsRepository.java
index 548d48e..522ca4d 100644
--- a/src/main/java/fr/unistra/sil/erp/back/repository/item/SqliteItemsRepository.java
+++ b/src/main/java/fr/unistra/sil/erp/back/repository/item/SqliteItemsRepository.java
@@ -21,7 +21,7 @@ public class SqliteItemsRepository extends SqliteRepository implements IItemsRep
      * Query used to select all items stored in the database.
      */
     private static final String SQL_GETALLITEMS =
-            "SELECT ref, name, price, subscriberPrice, category FROM items";
+            "SELECT id, name, price, subscriberPrice, category FROM items";
 
     /**
      * Query used to get all items stored in the database from a specific
@@ -47,7 +47,7 @@ public class SqliteItemsRepository extends SqliteRepository implements IItemsRep
         List<Item> res = new ArrayList<>();
         try {
             while (rs.next()) {
-                Item item = new Item(rs.getInt("ref"), rs.getString("name"),
+                Item item = new Item(rs.getInt("id"), rs.getString("name"),
                         rs.getBigDecimal("price"),
                         rs.getBigDecimal("subscriberPrice"),
                         rs.getInt("category"));
@@ -95,7 +95,7 @@ public class SqliteItemsRepository extends SqliteRepository implements IItemsRep
         List<Item> res = new ArrayList<>();
         try {
             while (rs.next()) {
-                Item item = new Item(rs.getInt("ref"), rs.getString("name"),
+                Item item = new Item(rs.getInt("id"), rs.getString("name"),
                         rs.getBigDecimal("price"),
                         rs.getBigDecimal("subscriberPrice"),
                         rs.getInt("category"));
diff --git a/src/main/java/fr/unistra/sil/erp/back/repository/stock/SqliteStocksRepository.java b/src/main/java/fr/unistra/sil/erp/back/repository/stock/SqliteStocksRepository.java
index e26eb05..a3b7d3d 100644
--- a/src/main/java/fr/unistra/sil/erp/back/repository/stock/SqliteStocksRepository.java
+++ b/src/main/java/fr/unistra/sil/erp/back/repository/stock/SqliteStocksRepository.java
@@ -26,7 +26,7 @@ public class SqliteStocksRepository extends SqliteRepository implements IStocksR
     private static final String SQL_GETSTOCKS =
             "SELECT s.id AS id, s.item AS item, " +
                     "i.name AS name, s.quantity AS quantity FROM stocks s " +
-                    "INNER JOIN items i ON s.item = i.ref";
+                    "INNER JOIN items i ON s.item = i.id";
 
     private static final String SQL_GETSTOCKFORITEM = SQL_GETSTOCKS +
             " WHERE item = ?";
-- 
GitLab