Skip to content
Snippets Groups Projects
Commit 5fa3ccf4 authored by BEAUVAIS ANTOINE's avatar BEAUVAIS ANTOINE
Browse files

Added categories in DB and API.

parent 9a8b103a
Branches
No related merge requests found
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS categories;
CREATE TABLE categories (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE items (
ref INTEGER PRIMARY KEY,
name TEXT NOT NULL,
price REAL NOT NULL,
subscriberPrice REAL NOT NULL
subscriberPrice REAL NOT NULL,
category INTEGER NOT NULL,
FOREIGN KEY (category) REFERENCES categories (id)
);
INSERT INTO items (ref, name, price, subscriberPrice)
VALUES (1, "Jus d'orange", 1.00, 0.50),
(2, "Coca-Cola", 1.50, 1.00);
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);
@ECHO OFF
WHERE sqlite3 > NUL
IF %ERRORLEVEL% NEQ 0 GOTO :installsqlite
sqlite3 dev.db ".read scripts/create-dev.sql"
IF %ERRORLEVEL% NEQ 0 GOTO :errorProcess
GOTO :end
:installsqlite
ECHO SQLite3 not found.
ECHO.
ECHO Make sure sqlite3.exe is in your PATH.
GOTO :end
:errorProcess
ECHO SQLite3 failed to process the database file.
:end
......@@ -32,20 +32,27 @@ public class Item {
*/
private final BigDecimal subscriberPrice;
/**
* This product's category identifier.
*/
private final int category;
/**
* Class constructor.
* @param ref 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)
BigDecimal subscriberPrice, int category)
{
this.ref = ref;
this.name = name;
this.price = price;
this.subscriberPrice = subscriberPrice;
this.category = category;
}
/**
......@@ -83,4 +90,13 @@ public class Item {
{
return this.subscriberPrice;
}
/**
* Returns the current item's category identifier.
* @return the category identifier.
*/
public int getCategory()
{
return this.category;
}
}
......@@ -23,7 +23,7 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
private static final String CONNECTION_URL = "jdbc:sqlite:dev.db";
private static final String SQL_GETALLITEMS =
"SELECT ref, name, price, subscriberPrice FROM items";
"SELECT ref, name, price, subscriberPrice, category FROM items";
private Connection conn;
......@@ -65,7 +65,8 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
{
Item item = new Item(rs.getInt("ref"), rs.getString("name"),
rs.getBigDecimal("price"),
rs.getBigDecimal("subscriberPrice"));
rs.getBigDecimal("subscriberPrice"),
rs.getInt("category"));
res.add(item);
}
} catch (SQLException ex) {
......
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