[#8] feat: 카페 신규 생성 로직 개발
- Cafe 관련 연관관계 엔티티 생성 로직 추가(CafeMenu, MenuOption, OptionDetail)
This commit is contained in:
@@ -61,7 +61,7 @@ class Cafe protected constructor(
|
||||
}
|
||||
|
||||
fun addCafeMenu(cafeMenu: CafeMenu) {
|
||||
cafeMenuList.add(cafeMenu)
|
||||
this.cafeMenuList.add(cafeMenu)
|
||||
cafeMenu.updateCafe(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "cafe_menu")
|
||||
class CafeMenu(
|
||||
class CafeMenu protected constructor(
|
||||
name: String,
|
||||
price: BigDecimal,
|
||||
) : BaseTimeEntity() {
|
||||
@@ -29,15 +29,22 @@ class CafeMenu(
|
||||
val menuOptionList: MutableList<MenuOption> = arrayListOf()
|
||||
|
||||
companion object {
|
||||
fun createCafeMenu(name: String, price: BigDecimal): CafeMenu {
|
||||
fun createCafeMenu(name: String, price: BigDecimal, menuOptionList: List<MenuOption>): CafeMenu {
|
||||
return CafeMenu(
|
||||
name = name,
|
||||
price = price
|
||||
)
|
||||
).apply {
|
||||
menuOptionList.forEach { this.addMenuOption(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCafe(cafe: Cafe) {
|
||||
this.cafe = cafe
|
||||
}
|
||||
|
||||
fun addMenuOption(menuOption: MenuOption) {
|
||||
this.menuOptionList.add(menuOption)
|
||||
menuOption.updateCafeMenu(this)
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,40 @@ import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "menu_option")
|
||||
class MenuOption(
|
||||
class MenuOption protected constructor(
|
||||
title: String
|
||||
) : BaseTimeEntity() {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Long = 0L,
|
||||
val id: Long = 0L
|
||||
|
||||
@Column(name = "title", nullable = false)
|
||||
val title: String,
|
||||
val title: String = title
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "menu_id", nullable = false)
|
||||
val cafeMenu: CafeMenu,
|
||||
var cafeMenu: CafeMenu? = null
|
||||
protected set
|
||||
|
||||
@OneToMany(mappedBy = "menuOption", fetch = FetchType.EAGER, cascade = [CascadeType.ALL])
|
||||
val optionDetailList: MutableList<OptionDetail>
|
||||
) : BaseTimeEntity()
|
||||
val optionDetailList: MutableList<OptionDetail> = arrayListOf()
|
||||
|
||||
companion object {
|
||||
fun createMenuOption(title: String, optionDetailList: List<OptionDetail>): MenuOption {
|
||||
return MenuOption(
|
||||
title = title
|
||||
).apply {
|
||||
optionDetailList.forEach { this.addOptionDetail(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCafeMenu(cafeMenu: CafeMenu) {
|
||||
this.cafeMenu = cafeMenu
|
||||
}
|
||||
|
||||
fun addOptionDetail(optionDetail: OptionDetail) {
|
||||
this.optionDetailList.add(optionDetail)
|
||||
optionDetail.updateMenuOption(this)
|
||||
}
|
||||
}
|
||||
@@ -6,18 +6,35 @@ import javax.persistence.*
|
||||
|
||||
@Entity
|
||||
@Table(name = "option_detail")
|
||||
class OptionDetail(
|
||||
class OptionDetail protected constructor(
|
||||
name: String,
|
||||
extraPrice: BigDecimal
|
||||
) : BaseTimeEntity() {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
val id: Long = 0L,
|
||||
val id: Long = 0L
|
||||
|
||||
@Column(name = "name", nullable = false)
|
||||
val name: String,
|
||||
val name: String = name
|
||||
|
||||
@Column(name = "extra_price", nullable = false)
|
||||
val extraPrice: BigDecimal,
|
||||
val extraPrice: BigDecimal = extraPrice
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "option_id", nullable = false)
|
||||
val menuOption: MenuOption
|
||||
): BaseTimeEntity()
|
||||
var menuOption: MenuOption? = null
|
||||
protected set
|
||||
|
||||
companion object {
|
||||
fun createOptionDetail(name: String, extraPrice: BigDecimal): OptionDetail {
|
||||
return OptionDetail(
|
||||
name = name,
|
||||
extraPrice = extraPrice
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateMenuOption(menuOption: MenuOption) {
|
||||
this.menuOption = menuOption
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ class CafeService(
|
||||
): Long {
|
||||
checkCafeExistedByName(name)
|
||||
|
||||
|
||||
|
||||
val cafeMenuList = cafeMenuRequestList.map {
|
||||
CafeMenu.createCafeMenu(it.name!!, it.price)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user