Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿš€ 2๋‹จ๊ณ„ - ๋ฆฌํŒฉํ„ฐ๋ง(๋ฉ”๋‰ด) #101

Open
wants to merge 26 commits into
base: dacapolife87
Choose a base branch
from

Conversation

dacapolife87
Copy link

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜
2๋‹จ๊ณ„ ๋ฉ”๋‰ด ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ผ๋‹จ ์ „์ฒด์ ์œผ๋กœ ๋ฆฌํŒฉํ† ๋ง์ด ์ง„ํ–‰์ด ์•„๋‹ˆ๋ผ
๋ฉ”๋‰ด ๋ถ€๋ถ„๋งŒ ๋ฆฌํŒฉํ† ๋ง์„ ์ง„ํ–‰ํ•˜๋‹ค๋ณด๋‹ˆ ์„œ๋น„์Šค๋ ˆ์ด์–ด๊ฐ€ ์ •๋ฆฌ๊ฐ€ ๋œ ๋œ ๊ธฐ๋ถ„์ด ๋“œ๋„ค์š”
์ตœ๋Œ€ํ•œ ๋ฉ”๋‰ด๊ด€๋ จ๋œ ๋ถ€๋ถ„ ๋„๋ฉ”์ธ ๋‚ด๋ถ€๋กœ ์˜ฎ๊ฒจ์„œ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๋„๋ก ์ˆ˜์ •ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
์ด๋ฒˆ์—๋„ ๋งŽ์€ ์ง€์ ๊ณผ ํ”ผ๋“œ๋ฐฑ ๋ถ€ํƒ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Copy link

@sah3122 sah3122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฉ”๋‰ด ๋ฆฌํŒฉํ† ๋ง ์ž˜ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ‘
๋ช‡๊ฐ€์ง€ ์ƒ๊ฐ๊ฑฐ๋ฆฌ๋ฅผ ๋‚จ๊ฒจ๋‘์—ˆ๋Š”๋ฐ, ์งˆ๋ฌธ์ด ์žˆ๋‹ค๋ฉด ํŽธํ•˜๊ฒŒ DM ์ฃผ์„ธ์š” ๐Ÿ™

columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_menu_to_menu_group")
)
private MenuGroup menuGroup;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MenuGroup Aggregate๋ฅผ ์ง์ ‘ ์ฐธ์กฐ๋กœ ๊ตฌํ˜„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š” ?

columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_menu_product_to_menu")
)
private List<MenuProduct> menuProducts;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MenuProduct ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜์„ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•ด๋ณด์„ธ์š” ๐Ÿ˜„

)
private List<MenuProduct> menuProducts;

public Menu() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JPA Entity์˜ ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋Š” protected ์ ‘๊ทผ์ œ์–ด์ž๋ฅผ ์„ ์–ธํ•˜๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š” ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/next-step/ddd-tactical-design/pull/101/files#r850475902 ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š” :)

public Menu() {
}

public Menu(PurgomalumClient purgomalumClient, String name, BigDecimal price, MenuGroup menuGroup, boolean displayed, List<MenuProduct> menuProducts) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menu๋ผ๋Š” Aggregate ๋Š” ์ •์˜๋œ ๋ถˆ๋ณ€์‹(๋ฉ”๋‰ด ๊ฐ€๊ฒฉ์€ ์†ํ•ด์žˆ๋Š” ์ƒํ’ˆ์˜ ๊ฐ€๊ฒฉ๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋“ฑ)์„ ๋ชจ๋‘ ๋งŒ์กฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
์–ด๋–ค ๋ถˆ๋ณ€์‹๋“ค์ด ์กด์žฌํ•˜๊ณ , ๋„๋ฉ”์ธ ๋กœ์ง์— ์–ด๋–ค ๋ฐฉ๋ฒ•์œผ๋กœ ๋…น์ผ์ˆ˜ ์žˆ๋Š”์ง€ ๊ณ ๋ฏผํ•ด๋ณด์„ธ์š”.


}

public void show() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฉ”๋‰ด๋ฅผ ๋…ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์„ ๋งŒ์กฑ์‹œํ‚ค์ง€ ๋ชปํ• ๊ฑฐ ๊ฐ™์•„์š”. ๐Ÿ˜„

foreignKey = @ForeignKey(name = "fk_menu_product_to_product")
name = "product_id",
columnDefinition = "varbinary(16)",
foreignKey = @ForeignKey(name = "fk_menu_product_to_product")
)
private Product product;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Product ๋„๋ฉ”์ธ์„ ์ง์ ‘์ฐธ์กฐ๋กœ ๊ตฌํ˜„ํ•œ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š” ?
์„œ๋กœ ๋‹ค๋ฅธ ์ปจํ…์ŠคํŠธ์˜ Aggregate๊ฐ„ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถ˜๋‹ค๋ฉด ์–ด๋–ค ์žฅ์ ์ด ์žˆ์„์ง€ ๊ณ ๋ฏผํ•ด๋ณด์„ธ์š” ๐Ÿ˜„

if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException();
}
public MenuResponse create(final MenuRequest request) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„์ง ์ค‘์š”ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ์„œ๋น„์Šค ๋ ˆ์ด์–ด์— ๋…ธ์ถœ๋˜์–ด ์žˆ๋Š”๊ฒƒ ๊ฐ™์•„์š”.
๋งŒ์•ฝ ํ˜„์žฌ ๊ตฌ์กฐ์—์„œ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋ถ„์ด ์„œ๋น„์Šค ๋ ˆ์ด์–ด์— ์žˆ๋Š” ๋กœ์ง์„ ๋ณด์ง€๋ชปํ•˜๊ณ  Menu ๋„๋ฉ”์ธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค๋ฉด Menu ๊ฐ์ฒด๋Š” ์™„์ „ํ•œ ๊ฐ์ฒด๋ผ๊ณ  ํ• ์ˆ˜ ์—†์„๊ฒƒ ๊ฐ™์•„์š” ๐Ÿ˜ข
๋…ธ์ถœ๋˜์–ด ์žˆ๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋„๋ฉ”์ธ ๋‚ด๋ถ€๋กœ ์˜ฎ๊ฒจ๋ณด์„ธ์š” ๐Ÿ˜„


@Table(name = "menu")
@Entity
public class Menu {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ƒˆ๋กญ๊ฒŒ ์ •์˜ํ•œ ํด๋ž˜์Šค๋“ค์˜ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•ด๋ณด์—ฌ์š”.
domain ํŒจํ‚ค์ง€์— ์กด์žฌํ•˜๋Š” ํด๋ž˜์Šค๋“ค์€ ๋‹จ์œ„ํ…Œ์ŠคํŠธ๋ฅผ ํ•„์ˆ˜๋กœ ์ž‘์„ฑํ•ด๋ณด์„ธ์š” ๐Ÿ˜„

@dacapolife87
Copy link
Author

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜
์˜ค๋žœ๋งŒ์— ๋ฆฌ๋ทฐ์š”์ฒญ๋“œ๋ฆฌ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
์˜ค๋žœ๊ธฐ๊ฐ„์„ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ ๋„์ €ํžˆ ์•ˆ๋˜๊ฒ ์–ด์„œ...
๊ณผ์ œ ์ดˆ๊ธฐ๋กœ ๋Œ์•„๊ฐ€์„œ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
์ฒซ ๋‹จ์ถ”๋ฅผ ์ž˜๋ชป์‹œ์ž‘ํ•ด์„œ ๋ฆฌํŒฉํ† ๋ง์„ ์ง„ํ–‰ํ•˜๋ ค๊ณ  ๋ณด๋‹ˆ ๊ณ„์†ํ•ด์„œ ๋” ์ž˜์•ˆ๋˜๊ฒŒ ๋˜๋„ค์š”
๊ทธ๋ž˜๋„ ๋‹ค์‹œ ๋ฏธ์…˜ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ง„ํ–‰ํ•ด๋ณด๋‹ˆ ์กฐ๊ธˆ์”ฉ ๋ฏธ์…˜์ง„ํ–‰์„ ํ• ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.
๋งŽ์€ ํ”ผ๋“œ๋ฐฑ ๋ฐ ์ง€์  ๋ถ€ํƒ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Copy link

@sah3122 sah3122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ์ž˜ํ•ด์ฃผ์…จ๋„ค์š” ๐Ÿ‘
๋ช‡๊ฐ€์ง€ ์ƒ๊ฐ๊ฑฐ๋ฆฌ๋ฅผ ์ถ”๊ฐ€๋กœ ๋‚จ๊ฒจ๋‘์—ˆ์–ด์š”.
์งˆ๋ฌธ์ด ์žˆ์œผ๋ฉด ์–ธ์ œ๋“ ์ง€ DM ์ฃผ์„ธ์š” ๐Ÿ˜„

import java.util.Objects;

@Embeddable
public class Price {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value Ojbect์˜ ๋ถˆ๋ณ€์„ฑ, ๊ฐ’ ๋™๋“ฑ์„ฑ์„ ์œ„ํ•ด Equals & HashCode ๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?

Comment on lines 36 to 38
public static Price add(Price totalPrice, Price addPrice) {
return new Price(totalPrice.price.add(addPrice.price));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static Price add(Price totalPrice, Price addPrice) {
return new Price(totalPrice.price.add(addPrice.price));
}
public Price add(Price addPrice) {
return new Price(this.price.add(addPrice.price));
}

static ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ๋ณด๋‹ค๋Š” ๊ฐ์ฒด์— ๋ฉ”์‹œ์ง€๋ฅผ ๋˜์งˆ์ˆ˜ ์žˆ๋„๋ก ์ƒํƒœ๊ฐ’์„ ์ด์šฉํ•˜๋Š”๊ฒƒ์ด ์ข‹์•„๋ณด์—ฌ์š” ๐Ÿ˜„

}
menu.setPrice(price);

List<Product> findProducts = productRepository.findAllByIdIn(menu.getProductIds());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Product ๋„๋ฉ”์ธ์ด MenuContext์— ์กด์žฌํ•˜์ง€ ์•Š๋„๋ก ๋„๋ฉ”์ธ ์„œ๋น„์Šค๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?

)
private List<MenuProduct> menuProducts;

public Menu() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/next-step/ddd-tactical-design/pull/101/files#r850475902 ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š” :)

public Menu() {
}

public Menu(PurgomalumClient purgomalumClient, UUID id, String name, Price price, UUID menuGroupId, boolean displayed, MenuProducts menuProducts) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ƒ์„ฑ์ž๊ฐ€ ๋‹ค์–‘ํ•ด์ง€๋Š”๊ฒฝ์šฐ ์ฃผ / ๋ถ€ ์ƒ์„ฑ์ž ๊ฐœ๋…์„ ๋„์ž…ํ•˜์—ฌ ๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?
https://jackjeong.tistory.com/148

@Embedded
private MenuGroupName name;

public MenuGroup() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/next-step/ddd-tactical-design/pull/101/files#r850475902
์œ„ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ํ™•์ธ๋ถ€ํƒ๋“œ๋ ค์š”

Comment on lines 32 to 36
private void validation(String name) {
if (Objects.isNull(name) || name.isEmpty()) {
throw new IllegalArgumentException("๋ฉ”๋‰ด๊ทธ๋ฃน์˜ ์ด๋ฆ„์€ Null๋˜๋Š” ๊ณต๋ฐฑ์ด ๋ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฉ”๋‰ด ๊ทธ๋ฃน ์ด๋ฆ„๊ณผ ๊ฐ™์€ ๋น„์ฆˆ๋‹ˆ์Šค ์š”๊ตฌ์‚ฌํ•ญ์€ MenuGroupName VO๊ฐ€ ๋‹ด๋‹นํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?

)
private Product product;
@Column(name = "product_id", columnDefinition = "varbinary(16)", nullable = false)
private UUID productId;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฉ”๋‰ด ๊ฐ€๊ฒฉ๊ณผ ๊ด€๋ จ๋œ ๋ถˆ๋ณ€์„ฑ์„ ์ง€ํ‚ค๊ธฐ ์œ„ํ•˜์—ฌ ํฌ๊ฒŒ 2๊ฐ€์ง€ ์ •๋„์˜ ๋ฐฉ์•ˆ์ด ์žˆ์„๊ฒƒ ๊ฐ™์•„์š”.

  1. MenuProduct์—์„œ Product์˜ ๊ฐ€๊ฒฉ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋‹ค.
  2. MenuProduct์—์„œ ๋„๋ฉ”์ธ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•˜์—ฌ Product์˜ ๊ฐ€๊ฒฉ Validation์„ ์ง„ํ–‰ํ•œ๋‹ค.

2๊ฐ€์ง€ ๋ฐฉ๋ฒ• ๋ชจ๋‘ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ , ์žฅ๋‹จ์ ์ด ์žˆ์–ด์š”.
์žฅ๋‹จ์ ์— ๋Œ€ํ•˜์—ฌ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ๋ฏธ์…˜ ์ง„ํ–‰ ํ•ด๋ณด์„ธ์š” ๐Ÿ˜„

์ด๋ฒˆ ๋ฏธ์…˜์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์—ฌ ์กฐ๊ธˆ์€ ๋‘๋ฃจ๋ญ‰์‹คํ•˜๊ฒŒ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‚จ๊ฒจ๋“œ๋ฆด๊ฒŒ์š”.
๊ตฌํ˜„์— ๋Œ€ํ•˜์—ฌ ๊ถ๊ธˆ์ฆ์ด ์žˆ์œผ์‹ค๋•Œ๋Š” ํŽธํ•˜๊ฒŒ Slack DM ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š” !

Comment on lines 3 to 5
import kitchenpos.common.domain.Price;
import kitchenpos.menus.ui.dto.MenuProductRequest;
import kitchenpos.products.tobe.domain.Product;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„๋ฉ”์ธ ์ฝ”๋“œ์—์„œ๋Š” ์™ธ๋ถ€ Context๊ฐ„ ๊ฒฐํ•ฉ๋„๊ฐ€ ์—†์œผ๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์•„์š”. ๐Ÿ˜„

import kitchenpos.menus.ui.dto.MenuProductRequest;
import kitchenpos.products.tobe.domain.Product;

import javax.persistence.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํŒจํ‚ค์ง€ ๋‚ด์— ๋ชจ๋“  ํด๋ž˜์Šค๋ฅผ importํ•  ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ์š” ?
https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports

@dacapolife87
Copy link
Author

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜
์ƒ๊ฐ์„ ์ข€ ๋งŽ์ด ํ•˜๋Š๋žด ๋ฆฌ๋ทฐ์š”์ฒญ์ด ๋Šฆ์—ˆ์Šต๋‹ˆ๋‹ค.
์ €๋ฒˆ์— ๋ฆฌ๋ทฐ์ฃผ์‹ ๋‚ด์šฉ์ค‘์— ์•„์ง ํ•˜๋‚˜๊ฐ€ ์ข€ ์ดํ•ด๊ฐ€ ๋˜์ง€์•Š์•„์„œ ์ƒ๊ฐ์ด ๋งŽ์•˜๋Š”๋ฐ์š”
'Product ๋„๋ฉ”์ธ์ด MenuContext์— ์กด์žฌํ•˜์ง€ ์•Š๋„๋ก ๋„๋ฉ”์ธ ์„œ๋น„์Šค๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š” ?' ์ด๋ถ€๋ถ„ ์ž…๋‹ˆ๋‹ค.
DM์œผ๋กœ๋„ ์งˆ๋ฌธ์„ ๋“œ๋ ธ์—ˆ๋Š”๋ฐ์š”
'Menu์™€ Product๋„๋ฉ”์ธ์ด ๊ณต์กดํ•˜๋Š” ๋„๋ฉ”์ธ ์„œ๋น„์Šค๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด๋Š”๊ฒƒ์„ ๊ถŒ์žฅ ๋“œ๋ฆฐ๊ฒƒ์ž…๋‹ˆ๋‹ค. ' ์ด๋ ‡๊ฒŒ ๋ง์”€์„ ํ•ด์ฃผ์…จ๋Š”๋ฐ
2๊ฐœ์˜ ๋„๋ฉ”์ธ์ด ๊ณต์กดํ•˜๋Š” ๋„๋ฉ”์ธ์„œ๋น„์Šค ๋ผ๋Š”๊ฑด
Menu์—์„œ Product๊ฐ€ ์ง์ ‘์ฐธ์กฐ๋ฅผ ํ•˜๊ฒŒ๋˜๋Š”๊ฑธ๊นŒ ๋ผ๋Š” ์ƒ๊ฐ๋„ ํ•ด๋ณด์•˜๋Š”๋ฐ
Menu๋ฅผ ์ƒ์„ฑํ•˜๋Š”๋ถ€๋ถ„์—์„œ๋Š” ์ง์ ‘์ฐธ์กฐ๋ฅผ ํ•  ๊ฐ์ฒด๋„ ์กด์žฌํ•˜์ง€์•Š์•„์„œ product๋ฅผ ์กฐํšŒํ•ด์„œ ๊ฐ€๊ฒฉ๋น„๊ต๋ฅผ ํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ์ด๊ณ ...
๋„์ €ํžˆ ๋‹ต์ด ์•ˆ๋‚˜์˜ค๋Š”๋“ฏํ•˜์—ฌ ์ผ๋‹จ ๋ฆฌ๋ทฐ์š”์ฒญ์„ ๋“œ๋ฆฌ๋ฉด์„œ ๋‹ค์‹œ ์งˆ๋ฌธ์„ ๋“œ๋ฆฌ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๋‚˜๋จธ์ง€ ํ”ผ๋“œ๋ฐฑ ์ฃผ์‹ ๋ถ€๋ถ„์€ ์ตœ๋Œ€ํ•œ ์ˆ˜์ •์„ ํ•ด๋ณด์•˜๋Š”๋ฐ์š”

๋ถ€์กฑํ•œ ๋ถ€๋ถ„์ด๋‚˜ ์ž˜๋ชป๋œ์ ์žˆ์œผ๋ฉด ๋งŽ์€ ์ง€์  ๋ถ€ํƒ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link

@sah3122 sah3122 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฆฌ๋ทฐ๊ฐ€ ๋งŽ์ด ๋Šฆ์–ด์ ธ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ™
์งˆ๋ฌธ์ฃผ์‹  ๋‚ด์šฉ์— ๋Œ€ํ•œ ๋‹ต๋ณ€์„ ๋‚จ๊ฒจ๋‘์—ˆ๋Š”๋ฐ ํ™•์ธ ๋ถ€ํƒ๋“œ๋ ค์š” !

this.menuProducts = menuProducts;
}

public MenuProducts(List<MenuProductDto> menuProductDtos, List<Product> products, Price menuPrice) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„๋ฉ”์ธ ์„œ๋น„์Šค ๊ตฌํ˜„์— ๊ด€ํ•ด ์–ด๋ ค์›€์„ ๊ฒช๊ณ  ์žˆ๋Š”๊ฒƒ ๊ฐ™์•„ ์ œ๊ฐ€ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœ ์‹œ์ผœ๋“œ๋ฆด๊ฒŒ์š”.
์šฐ์„  ์•ž์„œ ์ด์•ผ๊ธฐ ๋“œ๋ฆฐ๊ฒƒ์ฒ˜๋Ÿผ Aggreagte๊ฐ„ ๊ฐ„์ ‘์ฐธ์กฐ๋ฅผ ์ด์šฉํ•˜๋ฉด์„œ ์„œ๋กœ ๋‹ค๋ฅธ Context๊ฐ„์˜ ๊ฒฐํ•ฉ์„ ๋‚ฎ์ถ”๊ธฐ์œ„ํ•ด ๋„๋ฉ”์ธ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณค ํ•ด์š”.

์•„๋ž˜ ์ฝ”๋“œ๋Š” ์˜ˆ์‹œ์ด๋‹ˆ ์ฐธ๊ณ ๋งŒ ๋ถ€ํƒ๋“œ๋ ค์š” ๐Ÿ™
MenuProducts ๋ฅผ ์ƒ์„ฑํ• ๋–„ ์ƒํ’ˆ์ด ์กด์žฌํ•˜๋Š”์ง€, ๊ฐ€๊ฒฉ์ด ์œ ํšจํ•œ์ง€ ํŒ๋‹จํ•˜๊ธฐ ์œ„ํ•ด์„  ์•„๋ž˜์™€ ๊ฐ™์ด ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์„๊ฒƒ ๊ฐ™์•„์š”.

public MenuProducts(List<MenuProductDto> menuProductDtos, MenuCreateService menuCreateService, Price menuPrice) {
  menuCreateService.validate(menuProductDtos);
...
}

public class MenuCreateService {
  private final ProductRepository productRepository;

  public void validate(List<MenuProductDto> menuProductDtos) {
    menuProductDtos.forEach(dto -> {
      Product product = productRepository.findById(dto.getProductId());
      // ๋ฉ”๋‰ด ๊ฐ€๊ฒฉ๊ณผ ๊ด€๋ จ๋œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์‹คํ–‰
    })
  }

}

๊ฐœ์ธ์ ์œผ๋กœ๋Š” ์œ„์™€ ๊ฐ™์ด ์ƒ์„ฑ์ž ๋˜๋Š” ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„๋ฉ”์ธ ์„œ๋น„์Šค๋ฅผ ์ „๋‹ฌ ๋ฐ›์•„ ๋„๋ฉ”์ธ ์„œ๋น„์Šค ๋‚ด๋ถ€์—์„œ ์™ธ๋ถ€ Context์˜ ๋„๋ฉ”์ธ๊ณผ ํ˜‘๋ ฅํ•˜์—ฌ ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค.

์œ„ ์ฝ”๋“œ์—์„œ๋Š” Repository ๋ฅผ ์ฃผ์ž…๋ฐ›์•˜์ง€๋งŒ ์ด์™€ ๊ฐ™์€ ํ˜•ํƒœ๋Š” ๋™์ผํ•œ ํ”„๋กœ์ ํŠธ์—์„œ ํŒจํ‚ค์ง€ ๋‹จ์œ„๋กœ ์ปจํ…์ŠคํŠธ๊ฐ€ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์„๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด์—์š”.

๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๊ฐ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— Repository๊ฐ€ ์•„๋‹Œ ์™ธ๋ถ€ Client๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๊ฒ ์ฃ .

์œ„์ฒ˜๋Ÿผ ๊ตฌํ˜„ํ•˜๋Š”๊ฒƒ์— ๋Œ€ํ•œ ์žฅ์ ์€ Aggregate / Service ๋ ˆ์ด์–ด๋Š” ๋‹ค๋ฅธ Context์™€ ๊ฒฐํ•ฉ์ด ์—†์–ด์ง€๋ฉฐ ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒฝ์šฐ (๋ชจ๋†€๋ฆฌ์‹์•„ํ‚คํ…์ฒ˜์—์„œ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค๋กœ ๋ถ„๋ฆฌ๋˜๋Š” ๊ฒฝ์šฐ)์—๋Š” ๋„๋ฉ”์ธ์„œ๋น„์Šค์—์„œ ์ฃผ์ž…๋ฐ›๋Š” Repository์˜ ๊ตฌํ˜„์ฒด๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š”๊ฒƒ์œผ๋กœ ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค๋กœ์˜ ๋ถ„๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š”๊ฒƒ์ด์—์š”.

์šฐ์„  ์œ„์ฒ˜๋Ÿผ ๊ตฌํ˜„ํ•˜๋Š”๊ฒƒ์„ ๋„์ „ํ•ด๋ณด์„ธ์š” !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants