WS10-new
This commit is contained in:
@@ -1,61 +1,21 @@
|
||||
package dev.model;
|
||||
package dev.database;
|
||||
|
||||
public class OrderDetail {
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
private int id;
|
||||
private int orderId;
|
||||
private int menuItemId;
|
||||
private int quantity;
|
||||
private double price;
|
||||
public class DatabaseConnection {
|
||||
|
||||
public OrderDetail() {
|
||||
private static final String URL = getEnvOrDefault("DB_URL", "jdbc:postgresql://localhost:5432/postgres");
|
||||
private static final String USER = getEnvOrDefault("DB_USER", "postgres");
|
||||
private static final String PASSWORD = getEnvOrDefault("DB_PASSWORD", "password");
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return DriverManager.getConnection(URL, USER, PASSWORD);
|
||||
}
|
||||
|
||||
public OrderDetail(int id, int orderId, int menuItemId, int quantity, double price) {
|
||||
this.id = id;
|
||||
this.orderId = orderId;
|
||||
this.menuItemId = menuItemId;
|
||||
this.quantity = quantity;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(int orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public int getMenuItemId() {
|
||||
return menuItemId;
|
||||
}
|
||||
|
||||
public void setMenuItemId(int menuItemId) {
|
||||
this.menuItemId = menuItemId;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(int quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
private static String getEnvOrDefault(String key, String defaultValue) {
|
||||
String value = System.getenv(key);
|
||||
return (value != null && !value.isBlank()) ? value : defaultValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user