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๋‹จ๊ณ„ - ๋ฆฌํŒฉํ„ฐ๋ง(๋ฉ”๋‰ด) #144

Open
wants to merge 10 commits into
base: choieungi
Choose a base branch
from

Conversation

ChoiEungi
Copy link

์•ˆ๋…•ํ•˜์„ธ์š”, 2๋‹จ๊ณ„ ๋ฏธ์…˜ ์ œ์ถœ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ด๋ฒˆ ๋ฏธ์…˜์€ ๊ณ ๋ฏผํ•  ๋ถ€๋ถ„์ด ๋งŽ์•˜๋˜ ๊ฒƒ ๊ฐ™๋„ค์š”! ์ €๋Š” ์ง์ ‘์ ์œผ๋กœ ๋„๋ฉ”์ธ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด๊ฐ€๋ฉฐ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ์–ด์š” :)

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

๋˜ํ•œ, product์™€ menu context์˜ ๊ฒฐํ•ฉ์„ ๋Š๊ธฐ ์œ„ํ•ด์„œ event๋ฅผ ํ†ตํ•ด ๋ถ„๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ ๋กœ์ง์€ fake ๊ฐ์ฒด๋กœ ๊ฒ€์ฆํ•˜๊ธฐ ์–ด๋ ค์›Œ์„œ @SpringBootTest๋ฅผ ์ด์šฉํ•ด ํ†ตํ•ฉํ…Œ์ŠคํŠธ ๊ฒ€์ฆ์„ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

ํ˜น์‹œ ๋” ์ข‹์€ ์ œ์–ธ์ด ์žˆ์œผ์‹œ๋ฉด ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

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.

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

if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException();
}
public Menu 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.

๋ฏธ์…˜ ๋‚ด์šฉ๊ณผ๋Š” ์กฐ๊ธˆ ๋ฒ—์–ด๋‚ซ์ง€๋งŒ ์ œ๊ฐ€ Service Layer์— DTO๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœ ๋“œ๋ฆด๊ฒŒ์š”.
ํ˜„์žฌ๋Š” domain ํ•˜์œ„์— dto๋กœ ์ •์˜ํ•ด์ฃผ์…จ์ง€๋งŒ DTO๋ฅผ Layer ๊ฐ„ ๊ตฌ๋ถ„ ์—†์ด ์‚ฌ์šฉํ• ์ˆ˜๋„ ์žˆ์ง€๋งŒ Layer๊ฐ„ ๊ตฌ๋ถ„์„ ํ•œ๋‹ค๋ฉด
MenuRequest ๊ฐ์ฒด๋Š” UI Layer ๊ณ„์ธต์— ์†ํ•˜๋Š” DTO ๋ผ๊ณ  ๋ณผ์ˆ˜ ์žˆ์–ด์š”. (DTO๋ฅผ Layer๊ฐ„ ๊ตฌ๋ถ„ ์—†์ด ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์–ด๋Š์ˆœ๊ฐ„ ๋ถˆํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์นจ๋ฒ”ํ• ์ˆ˜ ์žˆ์–ด์š”.)
ํ˜„์žฌ Service Layer์— ์ƒ์œ„ Layer๊ฐ€ ์นจ๋ฒ•ํ•œ๊ฒƒ์„ ๋ณผ์ˆ˜ ์žˆ์ฃ .

๊ทธ๋กœ ์ธํ•ด ์ €ํฌ ํŒ€์—์„œ๋Š” Layer๊ฐ„ DTO ๋ถ„๋ฆฌ๋ฅผ ํ†ตํ•ด ๊ณ„์ธต์„ ์—„๊ฒฉํ•˜๊ฒŒ ๋‚˜๋ˆ„๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
UI Layer์—์„œ๋Š” Request / Response ์™€ ๊ฐ™์€ DTO ๋„ค์ด๋ฐ์„ ์‚ฌ์šฉํ•˜๊ณ , Service Layer ๋กœ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด์„  Command ์™€ ๊ฐ™์€ ๋„ค์ด๋ฐ์„ ์‚ฌ์šฉํ•˜๊ณค ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋งŒ ๋ถ€ํƒ๋“œ๋ ค์š” !

menu.setDisplayed(false);
}
}
productPriceChangeEventPublisher.publishEvent(price, productId);
Copy link

Choose a reason for hiding this comment

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

Application Event ํ™œ์šฉ ๐Ÿ‘
๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์œผ๋กœ Service Layer ์—์„œ Event ๋ฅผ ๋ฐœํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ๋„๋ฉ”์ธ ๋กœ์ง์ด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ ˆ์ด์–ด๋กœ ๋ถ„์‚ฐ๋˜๋Š”๊ฒƒ ๊ฐ™์•„์š”.
JPA ๊ธฐ์ค€ ๋„๋ฉ”์ธ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์†Œ๊ฐœ ๋“œ๋ฆด๊ฒŒ์š” ๐Ÿ˜„

https://www.baeldung.com/spring-data-ddd

Copy link

Choose a reason for hiding this comment

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

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

}

@Override
public void onApplicationEvent(ProductPriceChangeEvent event) {
Copy link

Choose a reason for hiding this comment

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

์ด๋ฒคํŠธ๋ฅผ ํ™œ์šฉํ•œ ๋Š์Šจํ•œ ๊ฒฐํ•ฉ ์ข‹๋„ค์š” ๐Ÿ‘

final List<MenuProduct> menuProducts = new ArrayList<>();
final Menu menu = new Menu(UUID.randomUUID(), request.getName(), request.getPrice(), menuGroup, request.isDisplayed(), menuProducts);

final List<MenuProductRequest> menuProductRequests = request.getMenuProducts();
final List<Product> products = productRepository.findAllByIdIn(
Copy link

Choose a reason for hiding this comment

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

๋ฉ”๋‰ด ์ปจํ…์ŠคํŠธ์—์„œ ์ƒํ’ˆ ์กฐํšŒ๋ฅผ ํ•˜๊ฒŒ๋œ๋‹ค๋ฉด ์ปจํ…์ŠคํŠธ๊ฐ„ ์นจ๋ฒ” ๋ฐ ๊ฒฐํ•ฉ์ด ๋ฐœ์ƒํ•˜์˜€๋‹ค๊ณ  ๋ณผ์ˆ˜ ์žˆ์–ด์š”.
์ด๋Ÿฌํ•œ ๊ฒฐํ•ฉ์„ ์ค„์—ฌ๋ณผ์ˆ˜ ์žˆ์„๊นŒ์š” ?

}

public void setPrice(final BigDecimal price) {
this.price = price;
public void changePrice(final BigDecimal price) {
Copy link

Choose a reason for hiding this comment

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

๋ณ€๊ฒฝํ•˜๋ ค๋Š” ๋ฉ”๋‰ด์˜ ๊ฐ€๊ฒฉ์ด ์ƒํ’ˆ ๊ธˆ์•ก์˜ ํ•ฉ๋ณด๋‹ค ์ ์€๊ฒƒ์„ ํ•ญ์ƒ ๋งŒ์กฑํ• ์ˆ˜ ์žˆ์„๊นŒ์š” ?

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