6938b764fc
Release package / release (push) Successful in 3m37s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Co-authored-by: TranHuuDanh <tranhuudanh@demonkernel.io.vn> Reviewed-on: #11
56 lines
1.1 KiB
Java
56 lines
1.1 KiB
Java
package com.drinkool.entities;
|
|
|
|
import jakarta.persistence.*;
|
|
import jakarta.transaction.Transactional;
|
|
import java.util.*;
|
|
|
|
@Entity
|
|
@Table
|
|
public class MenuItemEntity extends BaseEntity {
|
|
|
|
public String name;
|
|
public double price;
|
|
|
|
// Danh sách các nguyên liệu cấu thành món ăn này
|
|
@OneToMany(
|
|
mappedBy = "menuItem",
|
|
cascade = CascadeType.ALL,
|
|
orphanRemoval = true
|
|
)
|
|
public List<MenuItemIngredientEntity> ingredients = new ArrayList<>();
|
|
|
|
/**
|
|
* Thêm nguyên liệu vào món ăn với định lượng cụ thể
|
|
*/
|
|
@Transactional
|
|
public void addIngredient(
|
|
EateryInventoryItemEntity inventoryItem,
|
|
double requiredQty
|
|
) {
|
|
MenuItemIngredientEntity ingredient = MenuItemIngredientEntity.create(
|
|
this,
|
|
inventoryItem,
|
|
requiredQty
|
|
);
|
|
|
|
this.ingredients.add(ingredient);
|
|
|
|
this.persist();
|
|
}
|
|
|
|
/**
|
|
* Phương thức tiện ích để tạo nhanh Menu Item từ tên
|
|
*/
|
|
@Transactional
|
|
public static MenuItemEntity create(String name, double price) {
|
|
MenuItemEntity menu = new MenuItemEntity();
|
|
|
|
menu.name = name;
|
|
menu.price = price;
|
|
|
|
menu.persist();
|
|
|
|
return menu;
|
|
}
|
|
}
|