๐ 1๋จ๊ณ - ๋ฆฌํฉํฐ๋ง(์ํ)#241
Conversation
kyucumber
left a comment
There was a problem hiding this comment.
์๋ ํ์ธ์
๋ช๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒจ๋์์ผ๋ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค.
| this.purgomalumClient = purgomalumClient; | ||
| } | ||
|
|
||
| @Transactional |
There was a problem hiding this comment.
์ค์ํ ๋ถ๋ถ์ ์๋๋, ๋น ํธ๋ฆฌ์ง ์๋๋ก ํด๋์ค ๋ ๋ฒจ๋ก ์ด๋ ธํ ์ด์ ์ ๋ฌ์๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ๋ค์.
There was a problem hiding this comment.
๊ทธ๋ ๊ตฐ์ @transactional ์ด ์ค๋ณต์ผ๋ก ๋ฉ์๋์ ๋ถ์ด ์๋ค์
| @Service | ||
| public class ProductService { | ||
| private final ProductRepository productRepository; | ||
| private final ProductMenuService productMenuService; |
There was a problem hiding this comment.
์ธํฐํ์ด์ค๋ฅผ ํตํด Menu ์ปจํ ์คํธ์ ๊ฒฐํฉ์ ๋ฎ์ถฐ์ฃผ์ ๋ถ๋ถ์ด ์ข๋ค์ ๐
| } | ||
|
|
||
| @Override | ||
| public void validMenuDisplay(final UUID productId) { |
There was a problem hiding this comment.
๋ฉ์๋ ์ด๋ฆ์ valid์ด์ง๋ง ์ค์ ๋ก validate์ ๋ชฉ์ ์ด ์๋๋ผ ๊ฐ๊ฒฉ์ ํ์ธํ๊ณ ์กฐ๊ฑด์ ๋ง์ง ์์ผ๋ฉด menu์ ๋ ธ์ถ ์ฌ๋ถ(displayed)๊ฐ์ ๋ณ๊ฒฝํ๊ณ ์์ต๋๋ค. ๋ฉ์๋ ์ด๋ฆ์ ๋ณ๊ฒฝํ๋๊ฒ ์ด๋จ๊น์?
There was a problem hiding this comment.
changeMenuDisplay ๊ฐ์ ์ด๋ฆ์ผ๋ก ์์ ํ๋๋ก ํ๊ฒ ์ต๋๋ค.
| } | ||
|
|
||
| @Override | ||
| public void validMenuDisplay(final UUID productId) { |
There was a problem hiding this comment.
์ธํฐํ์ด์ค๋ฅผ ํตํด ๊ฒฐํฉ๋๋ฅผ ๋๋์ด ์ฃผ์ ๋ถ๋ถ์ ์ข์ผ๋ ์ง๊ธ์ ๊ตฌํ์ด๋ผ๋ฉด Spring์ ApplicationEvent๋ฅผ ์ฌ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋๋ค์.
There was a problem hiding this comment.
๋ง์ง๋ง ๊ฐ์๋ @eventlistener ๊ฐ์ ํด์ฃผ์๋๋ฐ ์จ๋ณด๋ฉด ์ข๊ฒ ๊ตฐ์ ใ ใ
| @Embedded | ||
| private ProductName name; | ||
|
|
||
| @Embedded | ||
| private ProductPrice price; |
| final Product product = productRepository.findById(productId) | ||
| .orElseThrow(NoSuchElementException::new); |
There was a problem hiding this comment.
์ด๋ฒ ๋ฏธ์ ์ ๋๋ฉ์ธ ์ชฝ๋ง ๋ฆฌํฉํฐ๋งํ๋๊ฑฐ๊ธด ํ์ง๋ง ์ฐธ๊ณ ๋ก ์ฝ๋ฉํธ ๋จ๊น๋๋ค.
NoSuchElementException์ด ๋ฐ์ํ๋ฉด ์ด๋ค ์๋ฌ ์๋ต์ด ๋๊ฐ๊ฒ ๋ ๊น์? ์ด์ ๊ด๋ จํด์ RestControllerAdvice ๋ฑ์ผ๋ก ์ฒ๋ฆฌํด์ค ํ์๋ ์์๊น์?
There was a problem hiding this comment.
GlobalRestController ์ฐ๋ฉด ๋ ์ ํํ ์๋ต๊ฐ์ ๋ฐ์ ๋ณผ ์ ์๊ฒ ๊ตฐ์ ใ ใ
| import java.math.BigDecimal; | ||
| import java.util.UUID; | ||
|
|
||
| public class ProductInfo { |
There was a problem hiding this comment.
์ง๊ธ ์๋์ ๊ฐ์ด ๊ตฌ์ฑํด์ฃผ์ ๊ฒ ๊ฐ๋ค์
- Product ๊ด๋ จ Request, Response
- ProductInto
- Product(Entity)
์ด๋ ๊ฒ ๋๋ฉด ProductInfo๋ผ๋ ๋๋ฉ์ธ ํด๋์ค์ ๋๋ฉ์ธ ๋ก์ง(Value Object ๋ฑ)์ด ์ ์ฉ๋์ด์ผ ํ์ง ์์๊น์? ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ ์ด์ด์ ๊ฒฐํฉ๋๊ณ ์๋ Entity๊ฐ ๋๋ฉ์ธ ๋ก์ง์ ๊ฐ์ง๋ ๊ฒ ๋ณด๋จ ๋๋ฉ์ธ ํด๋์ค๊ฐ ๋๋ฉ์ธ ๋ก์ง์ ๊ฐ์ง๋๊ฒ ์ ์ ํด๋ณด์ฌ์.
There was a problem hiding this comment.
DM์ผ๋ก๋ ๋๋ ธ์ง๋ง, Productinfo๊ฐ DTO ์ญํ์ ํ๊ณ ์ถ์ด์ ๋ง๋ ๊ฒ์ด๋ผ์, @kyucumber ๋ฆฌ๋ทฐ์ด๋ ๋ง์๋๋ก entity ๋ณด๋ค๋ vo๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํ๋๊ฒ์ด DB์ ์ํฅ์ ๋ ๊ฐ๊ฒ๊ฐ์ต๋๋ค ใ ใ
๋ฆ๊ฒ ์ ์ถํด์ ์ฃ์กํฉ๋๋ค
์๊ตฌ์ฌํญ๋๋ก, tobe ํจํค์ง๋ฅผ ๋ง๋ค์ด ์ถ๊ฐ๋๋ domain์ ๊ทธ๊ณณ์ ์ถ๊ฐํ์์ต๋๋ค.