Skip to content
Snippets Groups Projects
Commit 21dd4057 authored by GAYDAMAKHA MIKHAIL's avatar GAYDAMAKHA MIKHAIL
Browse files

:recycle: rename ref to id in Item model

parent d75552a9
2 merge requests!25Develop,!22:recycle: rename ref to id in Item model
......@@ -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"),
......
......@@ -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;
}
/**
......
......@@ -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"));
......
......@@ -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 = ?";
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment