chore: add eatery inventory item
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class EateryInventoryItemEntity extends BaseEntity {
|
||||
|
||||
public int quantity;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "inventory_item_id")
|
||||
public InventoryItemEntity inventoryItem;
|
||||
|
||||
// Create
|
||||
@Transactional
|
||||
public void add(String name, int quantity, String unit) {
|
||||
String itemName = name.toLowerCase();
|
||||
|
||||
InventoryItemEntity item = InventoryItemEntity.find(
|
||||
"name",
|
||||
itemName
|
||||
).firstResult();
|
||||
|
||||
// 2. Nếu chưa có thì mới tạo mới
|
||||
if (item == null) {
|
||||
item = new InventoryItemEntity();
|
||||
if (unit != null) {
|
||||
item.add(itemName, unit);
|
||||
} else {
|
||||
item.add(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
this.inventoryItem = item;
|
||||
this.quantity = quantity;
|
||||
|
||||
this.persist();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void add(String name, int quantity) {
|
||||
this.add(name, quantity, null);
|
||||
}
|
||||
}
|
||||
@@ -9,21 +9,19 @@ import jakarta.transaction.Transactional;
|
||||
public class InventoryItemEntity extends BaseEntity {
|
||||
|
||||
public String name;
|
||||
public int quantity;
|
||||
public String unit;
|
||||
|
||||
// Create
|
||||
@Transactional
|
||||
public void add(String name, int quantity, String unit) {
|
||||
public void add(String name, String unit) {
|
||||
this.name = name;
|
||||
this.quantity = quantity;
|
||||
this.unit = unit;
|
||||
|
||||
this.persist();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void add(String name, int quantity) {
|
||||
add(name, quantity, "unit");
|
||||
public void add(String name) {
|
||||
add(name, "unit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class MenuItemEntity extends BaseEntity {
|
||||
public String name;
|
||||
public double price;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user