This commit is contained in:
2026-07-08 12:59:53 +03:30
parent 5ea8a95fe7
commit d4b53abe3d
@@ -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; public class DatabaseConnection {
private int orderId;
private int menuItemId;
private int quantity;
private double price;
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) { private static String getEnvOrDefault(String key, String defaultValue) {
this.id = id; String value = System.getenv(key);
this.orderId = orderId; return (value != null && !value.isBlank()) ? value : defaultValue;
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;
} }
} }