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

๐Ÿš€ 1๋‹จ๊ณ„ - ๋ฆฌํŒฉํ„ฐ๋ง(์ƒํ’ˆ) #328

Open
wants to merge 2 commits into
base: sumiini
Choose a base branch
from

Conversation

sumiini
Copy link

@sumiini sumiini commented Feb 15, 2025

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜.
products ํŒจํ‚ค์ง€ ํ•˜์œ„์— tobe.domain ํŒจํ‚ค์ง€๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.
JpaProductRepository ๊ตฌํ˜„์ฒด ์ƒ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ž˜ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๐Ÿ™‚

Copy link

@Rok93 Rok93 left a comment

Choose a reason for hiding this comment

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

์ˆ˜๋ฏผ๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”. ๋„๋ฉ”์ธ ์ฃผ๋„ ์„ค๊ณ„ ๊ธฐ๋ณธ ์š”์†Œ ๋ฏธ์…˜์„ ํ•จ๊ป˜ํ•˜๊ฒŒ๋œ ๊น€๊ฒฝ๋ก์ž…๋‹ˆ๋‹ค.
1๋‹จ๊ณ„ ๋ฏธ์…˜ ์ž˜ ๊ตฌํ˜„ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค๋งŒ ํ˜„์žฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ธฐ๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ด๋„ค์š”. ๐Ÿ˜ข

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ธฐ๋™๋˜๋Š” ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”.
์ถ”๊ฐ€์ ์œผ๋กœ ๊ธฐ์กด์˜ API๋ฅผ ๋ฆฌํŒฉํ„ฐ๋งํ•˜์‹  ์ฝ”๋“œ๋กœ ๋Œ€์ฒดํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”.
๋˜ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ๋˜ํ•œ ๊ธฐ์กด์˜ ์„œ๋น„์Šค ๋กœ์ง์ด ์•„๋‹Œ ๋ฆฌํŒฉํ„ฐ๋งํ•œ ์„œ๋น„์Šค ๋กœ์ง์œผ๋กœ ๋Œ€์ฒดํ–ˆ์„ ๋•Œ, ๊ธฐ์กด์˜ ๋™์ž‘์„ ๋™์ผํ•˜๊ฒŒ ์ˆ˜ํ–‰ํ•˜๋Š”์ง€๋ฅผ ํ™•์ธํ•ด์ฃผ์…จ์œผ๋ฉดํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ™

์ด ๋ฏธ์…˜์€ ์‹ค์ œ๋กœ ์„œ๋น„์Šค์ค‘์ธ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ตœ๋Œ€ํ•œ ๋ฆฌํŒฉํ„ฐ๋ง์„ ์ง„ํ–‰ํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”. ๐Ÿ˜ƒ

๊ทธ ์™ธ์—๋„ ๋ช‡๋ช‡ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒจ๋‘์—ˆ์œผ๋‹ˆ ํ™•์ธ ๋ถ€ํƒ๋“œ๋ฆด๊ฒŒ์š”.

import java.util.Objects;
import java.util.UUID;

@Service
Copy link

Choose a reason for hiding this comment

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

ํ˜„์žฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋™์ด ์•ˆ๋˜๊ณ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„์š”.
๋‹ค์Œ ๋ฆฌ๋ทฐ ์š”์ฒญ ๋•Œ๋Š”, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ธฐ๋™๋˜๋Š” ์ƒํƒœ๊ฐ€ ๋˜๋„๋กํ•ด์ฃผ์„ธ์š”. ๐Ÿ˜ƒ

}

@Transactional
public Product create(final Product request) {
Copy link

Choose a reason for hiding this comment

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

๊ธฐ์กด์˜ ์„œ๋น„์Šค ๋กœ์ง์„ ์‚ฌ์šฉํ•˜๋˜ ์œ„์น˜๋“ค์„ ๋ฆฌํŒฉํ„ฐ๋งํ•œ ๋กœ์ง๋“ค์„ ๋Œ€์‹  ์‚ฌ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.

์ง€๊ธˆ์˜ ์ƒํƒœ์—์„œ๋Š” ๋ฆฌํŒฉํ„ฐ๋งํ•œ ์ฝ”๋“œ๋“ค์ด ์ด์ „์ฒ˜๋Ÿผ ์ž˜ ๋™์ž‘ํ• ์ง€์— ๋Œ€ํ•œ ํ™•์‹ ์ด ๋“ค์ง€ ์•Š๋Š”๋ฐ์š”. ๐Ÿค”
ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ๋˜ํ•œ ๋ณ€๊ฒฝ๋œ ProductService๋กœ ๋Œ€์ฒดํ•ด์ฃผ์‹  ๋’ค, ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๊ฐ€ ์ž˜ ๋Œ์•„๊ฐ€๋Š”์ง€ ํ™•์ธ์ด๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”. ๐Ÿ˜ƒ

throw new IllegalArgumentException();
}
final Product product = productRepository.findById(productId)
.orElseThrow(NoSuchElementException::new);
Copy link

Choose a reason for hiding this comment

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

์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ, ์ ์ ˆํ•œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋˜์ ธ์ค€๋‹ค๋ฉด ์—๋Ÿฌ๋ฉ”์‹œ์ง€๋ฅผ ํ†ตํ•ด์„œ ๋ฌธ์ œ์˜ ์›์ธ์„ ํŒŒ์•…ํ•˜๊ธฐ๊ฐ€ ๋” ์ˆ˜์›”ํ•ด์ง€์ง€ ์•Š์„๊นŒ์š”? ๐Ÿ˜ƒ

Suggested change
.orElseThrow(NoSuchElementException::new);
.orElseThrow(() -> new NoSuchElementException("์ƒํ’ˆ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. productId: " + productId));

import jakarta.persistence.Embeddable;
import kitchenpos.products.infra.PurgomalumClient;
@Embeddable
public class Name {
Copy link

Choose a reason for hiding this comment

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

README.md์— ์ ํžŒ ์šฉ์–ด ์‚ฌ์ „, ๋ชจ๋ธ๋ง์„ ๋ดค์„ ๋•Œ๋Š” Name์ด ์•„๋‹Œ DisplayedName์œผ๋กœ ์ •์˜ํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™์€๋ฐ์š”. ๐Ÿค”
ํ˜น์‹œ ์ด์ „ ๋ฏธ์…˜ ์ฝ”๋“œ or ๋ฌธ์„œ๋ฅผ ๊ฐ€์ง€๊ณ ์™€์•ผํ•˜๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด ํ•ด๋‹น PR close ํ›„, 0๋‹จ๊ณ„ PR์„ ์˜ฌ๋ ค์ฃผ์„ธ์š”!

}
final Product product = productRepository.findById(productId)
.orElseThrow(NoSuchElementException::new);
product.setPrice(price);
Copy link

Choose a reason for hiding this comment

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

setter๋ฅผ ์ด์šฉํ•˜๊ธฐ๋ณด๋‹ค๋Š”, ๋ณ€๊ฒฝ์˜ ์˜๋ฏธ๋ฅผ ๋“œ๋Ÿฌ๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ์ ์ ˆํžˆ ๋ฉ”์„œ๋“œ๋ช…์„ ๋„ค์ด๋ฐํ•ด๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Suggested change
product.setPrice(price);
product.changePrice(price);


@Entity
@Table(name = "product")
public class ProductEntity {
Copy link

Choose a reason for hiding this comment

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

์ˆœ์ˆ˜ ๋„๋ฉ”์ธ ๊ฐ์ฒด์™€ JPA์˜ Entity๋ฅผ ๋ถ„๋ฆฌํ•˜์…จ๊ตฐ์š”? ๐Ÿ‘

import jakarta.persistence.Embeddable;
import kitchenpos.products.infra.PurgomalumClient;
@Embeddable
public class Name {
Copy link

Choose a reason for hiding this comment

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

Name, Price์˜ ๊ฒฝ์šฐ VO๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”? ๐Ÿ˜ƒ

import java.math.BigDecimal;
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.

์ถ”ํ›„ ๋‹ค๋ฅธ ์ปจํ…์ŠคํŠธ์—์„œ๋„ Price๊ฐ€ ๋“ฑ์žฅํ•  ๊ฒƒ ๊ฐ™์€๋ฐ์š”.
๋ชจ๋‘ ๊ฐ™์€ Price๋ฅผ ์“ฐ๋Š”๊ฑธ๊นŒ์š”? ๊ทธ๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด ๋„ค์ด๋ฐ์ ์œผ๋กœ ๊ตฌ๋ถ„์„ ํ•ด๋‘๋Š”๊ฒŒ ์ข‹์ง€ ์•Š์„๊นŒ์š”? ex) ProductPrice

Comment on lines +36 to +43
final BigDecimal price = request.getPrice();
if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) {
throw new IllegalArgumentException();
}
final String name = request.getName();
if (Objects.isNull(name) || purgomalumClient.containsProfanity(name)) {
throw new IllegalArgumentException();
}
Copy link

Choose a reason for hiding this comment

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

Price, Name ๊ฐ’ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ๋งŒํ•ด๋„ ์ด ๊ฒ€์ฆ์€ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ˆ˜ํ–‰๋  ๊ฒƒ ๊ฐ™์€๋ฐ์š”. ๐Ÿค”
๋‘ ๊ฐ’ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ product์˜ ์ƒ์„ฑ์ž ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ํ†ตํ•ด ์ฃผ์ž…ํ•ด์„œ Product ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ๋ณ€๊ฒฝํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๐Ÿ˜‰

@sumiini
Copy link
Author

sumiini commented Feb 18, 2025

์•ˆ๋…•ํ•˜์„ธ์š” @Rok93 ๋ฆฌ๋ทฐ์–ด๋‹˜ !
๊ถ๊ธˆํ•œ ์‚ฌํ•ญ์ด ์žˆ์–ด ๋ฌธ์˜๋“œ๋ฆฝ๋‹ˆ๋‹ค.
๊ธฐ์กด ์‚ฌ์šฉํ•˜๋˜ Product๋ฅผ ์ˆœ์ˆ˜ ๋„๋ฉ”์ธ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค๋ฉด์„œ
Product, Price(ProductPrice), Name(ProductName)์œผ๋กœ ๋ถ„๋ฆฌ ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ด๋•Œ ๋ชจ๋“  ์—ฐ๊ด€๋œ Product์„œ๋น„์Šค๋กœ์ง๊ณผ ํ…Œ์ŠคํŠธ ๋กœ์ง ,Fixture์—์„œ ๋ชจ๋‘ ์—๋Ÿฌ ๋ฐœ์ƒํ•ด์„œ
์–ด๋””๋ถ€ํ„ฐ ์†์„๋Œ€์•ผํ• ์ง€ ๊ณ ๋ฏผ์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ณ ๋ฏผํ•˜๊ณ  ๋ฐฉํ–ฅ์„ ์žก๋‹ค ์‹œ๊ฐ„์ด ๋Š˜์–ด๋‚˜๊ณ , ์—๋Ÿฌ ๋ฐœ์ƒํ•  ๋•Œ ๋งˆ๋‹ค ๊ทธ๋ƒฅ ๊ณ ์น˜๋Š” ๋Š๋‚Œ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

ํ˜น์‹œ ์ด๋Ÿฐ ์ƒํ™ฉ์ผ ๋•Œ๋Š”
๋กœ์ง์„ ์–ด๋””์„œ๋ถ€ํ„ฐ ๊ณ ์น˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๋Š”๊ฒƒ์ด ์ข€ ๋” ํšจ์œจ์ ์ผ๊นŒ์š”?!๐Ÿ˜ฅ

@Rok93
Copy link

Rok93 commented Mar 1, 2025

@sumiini ๋‹˜ ์•ˆ๋…•ํ•˜์„ธ์š”.
์—๊ตฌ... ์งˆ๋ฌธ ๋‚จ๊ฒจ์ฃผ์‹  ๊ฒƒ์„ ์ด์ œ์„œ์•ผ ํ™•์ธํ–ˆ๋„ค์š”. ๐Ÿฅฒ (ํ˜น์‹œ ๋‹ค์Œ์—๋„ ์งˆ๋ฌธ์„ ๋‚จ๊ฒจ์ฃผ์…จ๋Š”๋ฐ, ๋‹ต๋ณ€์ด ์—†๋‹ค๋ฉด ์ถ”๊ฐ€์ ์œผ๋กœ DM์œผ๋กœ๋„ ๊ผญ ๋‚จ๊ฒจ์ฃผ์„ธ์š”. ๐Ÿ™)

๊ธฐ์กด Product์— ์˜์กดํ•˜๋Š” ๋กœ์ง๋“ค์ด ๋งŽ๋‹ค๋ณด๋‹ˆ ๋ง์”€ํ•˜์‹  ๊ฒƒ์ฒ˜๋Ÿผ ์–ด๋””์„œ๋ถ€ํ„ฐ ์ˆ˜์ •ํ•ด์•ผํ• ์ง€ ๊ณ ๋ฏผ์ด๋˜์‹ค ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”. ๐Ÿค”

์ €๋ผ๋ฉด Product์˜ ๋‚ด๋ถ€์˜ ์ƒํƒœ ๊ฐ’์˜ ํƒ€์ž…์€ ๋ฐ”๋€Œ๋”๋ผ๋„, ๊ธฐ์กด์˜ ๋™์ž‘์„ ์œ ์ง€ํ•˜๋„๋ก ํ•  ๊ฒƒ ๊ฐ™์•„์š”.

์ƒ์„ฑ์ž ์˜ค๋ฒ„๋กœ๋”ฉ, getter, setter์˜ ๋ฐ˜ํ™˜ ํƒ€์ž… ํ˜น์€ ๋ฉ”์„œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ธฐ์กด๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ฐ›๋˜, ๋‚ด๋ถ€์ ์œผ๋กœ๋Š” VO ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•ด์„œ ํ• ๋‹นํ•˜๋„๋ก ์ˆ˜์ •ํ•œ๋‹ค๊ฑฐ๋‚˜, (๋ฌผ๋ก  ์ถ”ํ›„ setter๋Š” ๊ฐ€๊ธ‰์  ์ œ๊ฑฐ๋ฅผ ํ•˜๋„๋ก ๋ฆฌํŒฉํ„ฐ๋งํ•˜๊ณ  ์‹ถ์„ ๊ฒƒ ๊ฐ™์•„์„œ, @Deprecated ์ฃผ์„์„ ์ถ”๊ฐ€ํ•ด๋‘๊ณ  ์ถ”ํ›„ ๋ฆฌํŒฉํ„ฐ๋งํ•  ๋•Œ, ๊ฐœ์„ ํ•ด๋ณผ ๊ฒƒ ๊ฐ™์•„์š”)

์•„๋งˆ Fixtureํ•จ์ˆ˜๋„ ์ง€๊ธˆ์€ setter๋ฅผ ํ†ตํ•ด์„œ fixture๋ฅผ ์ƒ์„ฑํ•˜๊ณ ์žˆ์„ ๊ฒƒ ๊ฐ™์€๋ฐ setter๊ฐ€ ๊ธฐ์กด์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•ด๋„ ๋™์ผํ•˜๊ฒŒ ๋™์ž‘ํ•˜๋„๋ก ํ˜ธํ™˜์„ฑ๋งŒ ์œ ์ง€ํ•ด์ค€๋‹ค๋ฉด ๋‹น์žฅ์— ์ปดํŒŒ์ผ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋Š” ๋ถ€๋ถ„์€ ์ ์„ ๊ฒƒ ๊ฐ™์•„์š”. ๐Ÿค”

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

์ •๋ง์ •๋ง ์ตœํ›„์˜ ์ˆ˜๋‹จ์œผ๋กœ ๋„ˆ๋ฌด ์˜์กด์„ฑ์ด ๋งŽ์ด ์—ฎ์—ฌ์žˆ์–ด ์–ด๋ ต๋‹ค๋ฉด ๋ณ„๋„์˜ Product ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์„œ ์™„์ „ํžˆ ์ƒˆ๊ฒƒ์œผ๋กœ ๊ฐˆ์•„ ์—Ž์€ ๋’ค, ๋ณ€๊ฒฝ์„ ํ•ด์ค„ ๊ฒƒ ๊ฐ™๋„ค์š”.

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