Add StockExpected for Articles

This commit is contained in:
Tim
2025-06-12 08:22:00 +02:00
parent 8ff98defa3
commit 38f9ec69ae
5 changed files with 21 additions and 11 deletions

View File

@@ -20,6 +20,7 @@ public class ArticleModel {
private int price100;
private int discount100;
private int stock;
private int stockExpected;
private String category;
private double rating;
}

View File

@@ -29,6 +29,10 @@ public class Article {
@Column(name = "stock", nullable = false)
private Integer stock;
@Min(0)
@Column(name = "stockExpected", nullable = false)
private Integer stockExpected;
@Column(name = "name", nullable = false)
private String name;

View File

@@ -90,6 +90,7 @@ public class ArticleServiceImpl implements ArticleService {
article.getPrice100(),
article.getDiscount100(),
article.getStock(),
article.getStockExpected(),
article.getCategory(),
calculateAverageRating(article.getReviews())
);

View File

@@ -4,13 +4,16 @@ CREATE TABLE IF NOT EXISTS Articles
id INTEGER PRIMARY KEY NOT NULL,
uuid TEXT UNIQUE NOT NULL, -- UUID
stock INTEGER NOT NULL DEFAULT 0,
stockExpected INTEGER NOT NULL DEFAULT 100,
name TEXT NOT NULL,
description TEXT NULL, --in html
price100 INTEGER NOT NULL, -- in cents
discount100 INTEGER NULL, -- in percent
category TEXT NULL,
CONSTRAINT c_stock CHECK ( stock >= 0 )
CONSTRAINT c_stock CHECK ( stock >= 0 ),
CONSTRAINT c_stockExpected CHECK ( stockExpected >= 0 ), --inactive in current version
CONSTRAINT c_discount100 CHECK ( discount100 IS NULL OR 0 <= discount100 AND discount100 <= 100 ) --inactive in current version
);
-- article images
@@ -43,16 +46,6 @@ CREATE TABLE IF NOT EXISTS Customers
zip TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS Orders
(
id INTEGER PRIMARY KEY NOT NULL,
customer_id INTEGER NOT NULL,
time INTEGER NOT NULL, --unix millis or epoch, TBD
FOREIGN KEY (customer_id) REFERENCES Customers (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Accounts
(
id INTEGER PRIMARY KEY NOT NULL,
@@ -66,6 +59,17 @@ CREATE TABLE IF NOT EXISTS Accounts
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Orders
(
id INTEGER PRIMARY KEY NOT NULL,
customer_id INTEGER NOT NULL,
time INTEGER NOT NULL, --unix millis or epoch, TBD
status INTEGER NOT NULL, --enum, see java or JS
FOREIGN KEY (customer_id) REFERENCES Customers (id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS OrderItems
(
id INTEGER NOT NULL PRIMARY KEY,