-
Notifications
You must be signed in to change notification settings - Fork 164
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
๐ 3๋จ๊ณ - ๋ฆฌํฉํฐ๋ง(๋งค์ฅ ์์ฌ ์ฃผ๋ฌธ) #322
base: hoa0217
Are you sure you want to change the base?
Conversation
- JPA Entity์๋ ๋ถ์ผ ์ ์๋ค.
- MenuProducts๋ MenuPrice๋ฅผ ๋ชฐ๋ผ๋ ๋๋ค. ์์กด์ฑ ์ ๊ฑฐ.
- VO(NumberOfGuest, OrderTableName)์ ๊ฐ๋๋ค.
- ํด๋น ์๋์ ๋ฉ๋ด์ ๋ํ ์๋์ด ์๋, ๋ฉ๋ด์ํ์์ ์ํ์ ๋ํ ์๋์ด๋ค.
- ์ฃผ๋ฌธํด๋์ค๋ฅผ ์์๋ฐ์ผ๋ฉฐ ๋งค์ฅ์ฃผ๋ฌธ์ฉ ๋น์ง๋์ค๋ก์ง์ ๊ฐ๋๋ค.
- ๋งค์ฅ์ฃผ๋ฌธ์ ์์ฑํ๋ค
- dto์ ์๋ ๋ถ๋ณ์ ๊ฒ์ฆ์ ๋๋ฉ์ธ์ผ๋ก ์ฎ๊ธด๋ค.
- dto์ ์๋ ๋ถ๋ณ์ ๊ฒ์ฆ์ ๋๋ฉ์ธ์ผ๋ก ์ฎ๊ธด๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์ ์ ํ๋ :)
3๋จ๊ณ ๋ฏธ์
์ํด์ฃผ์
จ์ด์
๋ช ๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒผ์ต๋๋ค
ํ์ธํ๊ณ ๋ค์ ์์ฒญํด ์ฃผ์ธ์ ๐
private void validateMenuProducts(List<MenuProduct> menuProducts, List<Product> products) { | ||
if (menuProducts == null || products == null) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
if (products.size() != menuProducts.size()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
if (menuProducts.isEmpty()) { | ||
throw new IllegalArgumentException(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ ์ด์์ ๋๋ฉ์ธ์ด ์ฎ์ธ๋ค๋ฉด ๋๋ฉ์ธ ์๋น์ค๋ฅผ ํ์ฉํด ๋ณด์๋ ์ข์ ๊ฒ ๊ฐ๋ค์ :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋๋ฉ์ธ ์๋น์ค ๋์ถํด๋ณด๊ฒ ์ต๋๋ค!
public Stream<MenuProduct> stream() { | ||
return menuProducts.stream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stream ์ผ๋ก ๋ฐํํ ์ด์ ๊ฐ ์์๊น์?
Stream ์ผ๋ก ๋ฐํ ์ ์ด๋ค ์ฅ๋จ์ ์ด ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฅ์ ์ผ๋ก Stream์ผ๋ก ๋ฐํ ์ getter๋ฅผ ์ฐ์ง์๊ณ ์ผ๊ธ์ปฌ๋ ์
์ ํ์ํ ์ ์์ต๋๋ค~
๋จ์ ์ผ๋ก๋.. for๋ฌธ์ ๋๋ฆฌ๋ ๊ฒ๋ณด๋ค ์ฑ๋ฅ์ด ์์ข์ผ๋ ค๋์ ใ
ใ
๋ํ ๋๋ฒ๊น
์ด ์ด๋ ค์ธ ์ ์๊ฒ ๋ค์!
์ผ๋จ Iterable์ ๊ตฌํํ์ผ๋ ํด๋น ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋๋ก ์์ ํ๊ฒ ์ต๋๋ค!
ํน ์ ๊ฐ ๋ชจ๋ฅด๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ์กฐ์ธ๋ถํ๋๋ฆฝ๋๋ค!
public List<UUID> getMenuIds() { | ||
return orderLineItems.stream().map(OrderLineItemRequest::getMenuId).toList(); | ||
} | ||
|
||
public List<OrderLineItem> toOrderLineItems(List<Menu> menus, OrderType orderType) { | ||
return orderLineItems.stream() | ||
.map(orderLineItem -> orderLineItem.toStore(findMenu(menus, orderLineItem), | ||
orderType)).toList(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ์ธ์ ์ผ๋ก Dto ์์ ๋น์ฆ๋์ค ๋ก์ง์ ์ต๋ํ ๋ฐฐ์ ํ๋ ํธ์ธ๋ฐ์ :)
์ ์ ์๊ฐ์ Dto ๋ ๊ฐ์ฒด๋ผ๊ธฐ ๋ณด๋จ ๋ฐ์ดํฐ ์ ๋ฌ์ ํด์ฃผ๋ ๊ตฌ์กฐ์ฒด์ ๊ฐ๊น๋ค๊ณ ์๊ฐํ๊ณ ์์ต๋๋ค
์ ํ๋์ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ง์ต๋๋ค. DTO๋ ๋ฐ์ดํฐ ์ ๋ฌ์ฉ ๊ฐ์ฒด์ด์ง ๋น์ง๋์ค๋ก์ง์ ๋๋ฉ์ธ๊ณ์ธต์์ ๊ฐ์ ธ์ผํฉ๋๋ค. ๋น์ง๋์ค๋ก์ง์ ๋๋ฉ์ธ์ผ๋ก ์ํฐํฐ ์์ฑ ์ฑ ์์ ์ดํ๋ฆฌ์ผ์ด์ ์ผ๋ก ์ฎ๊ธฐ๊ฒ ์ต๋๋ค!
private Menu findMenu(List<Menu> menus, OrderLineItemRequest orderLineItem) { | ||
return menus.stream().filter(menu -> menu.getId().equals(orderLineItem.getMenuId())) | ||
.findFirst().orElseThrow((NoSuchElementException::new)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dto ์์ ๋ค๋ฅธ ์์ญ์ ๋๋ฉ์ธ์ ์์กดํ๊ณ ์๋ ๊ฒ ๊ฐ๋ค์
Order ๋ผ๋ ์์ญ์์ Menu ์ ๋ํ ๋๋ฉ์ธ์ ๊ฐ์ง๊ณ ์๋ค๋ฉด ์ด๋ค ๋จ์ ์ด ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ผ๋จ DTO์์ ์ํฐํฐ ์์ฑ์ ๋ํ ์ฑ
์์ ์ ๊ฑฐํ๋๋กํ๊ฒ ์ต๋๋ค!
๊ทธ๋ฌ๋ OrderLineItem์ด menuId์ ๋ํ ์ฐธ์กฐ๋ฅผ ๊ฐ์ง๊ณ ์๋ค๋ณด๋.. ์ฌ๋ฐ๋ฅธ Menu์ธ์ง ์๋์ง ๊ฒ์ฆ์ ํ์ํ ๊ฑฐ๊ฐ์๋ฐ ํฉํ ๋ฆฌ ํด๋์ค๋ฅผ ๋์ถํ์ฌ ํด๋น ์์
์ ์งํํ๋๊ฒ ์ข์ผ๋ ค๋์ใ
ใ
OrderLineItemMapperํด๋์ค(์ดํ๋ฆฌ์ผ์ด์ ์๋น์ค)๋ฅผ ๋์ถํด์ ํด๋น ์์ ์ ์งํํ์์ต๋๋ค!
@Column(name = "type", nullable = false, columnDefinition = "varchar(255)") | ||
@Enumerated(EnumType.STRING) | ||
private OrderType type; | ||
|
||
@Column(name = "status", nullable = false, columnDefinition = "varchar(255)") | ||
@Enumerated(EnumType.STRING) | ||
private OrderStatus status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ชจ๋ธ๋ง์ ๋ณด์์ ๋๋ ์ฃผ๋ฌธ ์ ํ์ ๋ฐ๋ผ ํ์ํ ์ฃผ๋ฌธ ์ํ ๊ฐ์ด ๋ค๋ฅด๋ค๋ ๊ฑธ ์ธ์งํ์
จ๋๋ฐ์~
๊ทธ๋ผ OrderType
๊ณผ OrderStatus
๋ ๊ณตํต์ผ๋ก ๋ณผ ์ ์์๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋๊ฐ๋ฅผ ๋ถ๋ฆฌํ ๊น ๊ณ ๋ฏผ์ ํ์ง๋ง, Order๋ผ๋ ์ถ์ํด๋์ค์์ ๊ณตํต์ผ๋ก ์ฐ์ด๋ ์์ฑ์ด ๋ง๋ค๊ณ ํ๋จ์ ํ์ต๋๋ค.
- OrderType: OrderType์ ๊ฒฝ์ฐ Order๋ฅผ ์์ํ๋ ํด๋์ค ํ์ ์ ๊ตฌ๋ถํ๋ ์ปฌ๋ผ์ผ๋ก ์ฌ์ฉ๋๊ณ ์์ด ์ ๊ฐ ์์์ ์ ํํ ์ด์ common์ ์์ ํ์๊ฐ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
- OrderStatus: ์ฃผ๋ฌธ ์ข ๋ฅ๋ณ๋ก ๋ค๋ฅธ EnumType์ ์ฐ๊ฒ๋๋ฉด ์์ ์ ์ฑ๊ธํ ์ด๋ธ์ ๋ต์ ๋ชป์ฐ๊ณ ํ ์ด๋ธ์ ๋ถ๋ฆฌํด์ผํ๋๋ผ๊ตฌ์.. ๋ํ ์ค๋ณต๋๋ ์ํ๋ค์ด ๋ค์๋ก ์กด์ฌํ๋๋ฐ ์ด๋ฅผ ๋ฐ๋ก ํด๋์ค๋ก ๋นผ๋๊ฒ ๋ง๋๊ฑธ๊น?๋ผ๋ ๊ณ ๋ฏผ์ด ๋ค์์ต๋๋ค.
import kitchenpos.orders.common.domain.tobe.OrderLineItem; | ||
|
||
@Entity | ||
public class StoreOrder extends Order { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ถ์ ํด๋์ค์ ํ์ฉ ๐
๋ค๋ฅธ ์ฃผ๋ฌธ ํ์
๋ค๋ ์ถ๊ฐํด๋ณด๋ฉด ์ด๋จ๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ต ์ถ๊ฐ ํ ๋ฆฌ๋ทฐ ์์ฒญํ๊ฒ ์ต๋๋ค!! ๊ฐ์ฌํฉ๋๋ค
- dto์ ์ํฐํฐ ์์ฑ๋ก์ง ์ ๊ฑฐ
โฆValidator ํด๋์ค๋ช ๋ณ๊ฒฝ
์๋ ํ์ธ์ ๋ฆฌ๋ทฐ์ด๋.
๋งค์ฅ ์์ฌ ์ฃผ๋ฌธ ๋ฆฌํฉํ ๋ง ์๋ฃํ์ฌ PR ์ฌ๋ฆฝ๋๋ค.
tobe ํจํค์ง๋ฅผ ๋ง๋ค์ด์ OrderTable, StoreOrder๋ฅผ ์์ ํ ํ application ๊ณ์ธต๊น์ง ์์ ์๋ฃํ์์ต๋๋ค.
common ํจํค์ง์ Order๋ผ๋ abstract class๋ฅผ ๋ง๋ค์ด์ ์ด๋ฅผ ์์๋ฐ์ ๊ฐ ์ฃผ๋ฌธ, ๋ฐฐ๋ฌ, ํฌ์ฅ Order ์ํฐํฐ๋ฅผ ๊ตฌํํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํด๋ณด๋ คํ์์ต๋๋ค. ๋ํ Menu๋ฆฌํฉํ ๋ง์ ํ์์ฑ์ด ๋๊ปด์ ธ ์๋์ ๊ฐ์ด ๊ฐ์ ํ์ต๋๋ค.
๊ฐ์ฌํฉ๋๋ค!