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

[김대겸] Step2 PR #681

Merged
merged 68 commits into from Dec 16, 2022
Merged

[김대겸] Step2 PR #681

merged 68 commits into from Dec 16, 2022

Conversation

Gyeom
Copy link

@Gyeom Gyeom commented Dec 13, 2022

안녕하세요 리뷰어님,

정말 힘들었던 미션이었습니다 ㅠㅠㅠㅠ

  1. 도메인 생성 관련 테스트 코드 작성
  2. 서비스 레이어에 있던 비즈니스 로직을 각 도메인에 책임 부여
  3. dao 정상 동작을 위해, dao호출 인터페이스를 매개변수로 넘겨 일단 비즈니스 로직이 정상적으로 동작되도록 유지
  4. DTO 개선 및 테스트 코드 리팩토링 (DTO가 변경되면서 계속 테스트코드 에러발생)
  5. Price, Quantity 등 원시값 포장 클래스 생성 및 테스트 코드 리팩토링
  6. 네이밍, 예외처리 등 컨벤션 관련해서 전반적으로 검토
  7. 부족한 도메인 테스트 코드 작성

크게는 위와 같은 순서로 코드를 작성하도록 노력했습니다.
한기능의 한개의 커밋으로 개발하고 싶었지만, 다른 클래스에 참조가 되는 부분이 많다보니 많이 헤멨습니다 ㅠㅠ

리팩토링에 대해 정말 많이 느끼고 배울 수 있었던 미션이었습니다.

이번 리뷰도 잘 부탁드립니다:)

daegyeom.kim added 30 commits December 11, 2022 11:58
Copy link
Member

@limwoobin limwoobin left a comment

Choose a reason for hiding this comment

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

안녕하세요 대겸님
2단계 미션 잘 진행해주셨습니다 👍👍
수정된 코드량도 어마어마하고 정말 고생많으셨어요!

고려해보면 좋을만한 부분들이 있어 코멘트 남겨드렸습니다.
확인하시고 다시 요청부탁드립니다!
추가로 고민되거나 의논하고싶은 부분이 있다면 언제든 편하게 dm주세요 ㅎㅎ

public MenuGroup create(final MenuGroup menuGroup) {
return menuGroupDao.save(menuGroup);
public MenuGroupResponse create(final MenuGroupRequest request) {
return MenuGroupResponse.from(menuGroupRepository.save(MenuGroup.of(request.getName())));
Copy link
Member

Choose a reason for hiding this comment

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

라인하나에 너무 많은 로직이 함축되어있네요 ㅎㅎ
중간에 변수로 한번 빼면은 보다 가독성이 좋아지지않을까 싶습니다!

Copy link
Author

Choose a reason for hiding this comment

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

지금 보니 그렇네요 ㅎㅎ 중간에 변수를 한번 빼도록 하겠습니다~!

Comment on lines 50 to 59
private List<MenuProduct> findAllMenuProductsByProductId(List<MenuProductRequest> menuProductRequests) {
return menuProductRequests.stream()
.map(menuProductRequest -> menuProductRequest.toMenuProduct(findProductById(menuProductRequest.getProductId())))
.collect(Collectors.toList());
}

return menus;
private Product findProductById(final Long id) {
return productRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException(id + "에 해당하는 상품을 찾을 수 없습니다."));
}
Copy link
Member

Choose a reason for hiding this comment

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

productId만 추출해 inquery로 개선해볼 수 있을것같습니다 ㅎㅎ

Copy link
Author

@Gyeom Gyeom Dec 14, 2022

Choose a reason for hiding this comment

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

음 그렇게 되면 toMenuProduct함수를 통해 사용되는 quantity를 사용할 수 있을지... 고민입니다 ㅠㅠ

Copy link
Member

Choose a reason for hiding this comment

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

toMenuProduct는 그대로 quantity를 사용하고
in query로 조회한 데이터의 사이즈와 요청받은 사이즈를 비교해 예외를 처리해보면 어떨까 싶습니다 ㅎㅎ
현재 id를 예외메시지에 같이 나타내고 있어 중간에 몇가지 과정이 더 필요할 수 있겠군요 ㅠ

Comment on lines 56 to 58
if (Objects.isNull(orderLineItems)) {
throw new IllegalArgumentException("요청정보에 주문정보가 존재하지 않습니다.");
}
Copy link
Member

Choose a reason for hiding this comment

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

빈 컬렉션이면 해당 예외에 안걸리지 않을까요? size로도 같이 체크해보심 좋을것같습니다 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

이 부분도 수정하도록 하겠습니다~! 감사합니다 :)

for (final Order order : orders) {
order.setOrderLineItems(orderLineItemDao.findAllByOrderId(order.getId()));
}
private List<Long> mapToMenuIds(final List<OrderLineItemRequest> orderLineItems) {
Copy link
Member

Choose a reason for hiding this comment

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

id만 추출하는로직으로 보이는데 메소드명이 안맞는것같아요!

Copy link
Author

Choose a reason for hiding this comment

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

좀 더 명확한 의미를 갖고 있는 메소드명을 고민해서 변경하도록 하겠습니다~!

public OrderResponse create(final OrderRequest request) {
Long orderTableId = request.getOrderTableId();
OrderTable orderTable = orderTableRepository.findById(orderTableId)
.orElseThrow(() -> new IllegalArgumentException(orderTableId + "에 해당하는 주문테이블을 찾을 수가 없습니다."));
Copy link
Member

Choose a reason for hiding this comment

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

id도 같이 예외메시지에 포함하신거 좋네요 ㅎㅎ
다만 직접스트링으로 선언하는것 보다는 별도의 예외메시지를 관리하는 클래스나 enum을 고려해보시는건 어떨까요??

Copy link
Author

Choose a reason for hiding this comment

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

넵 enum으로 예외메시지 관리할 수 있도록 수정하겠습니다 ~!

public class OrderResponse {
private Long id;
private final Long orderTableId;
private final String orderStatus;
Copy link
Member

Choose a reason for hiding this comment

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

enum을 사용안하고 String으로 사용하신 이유가있나요??

Copy link
Author

Choose a reason for hiding this comment

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

나중에 바꿔야지 하고 미루다가 잊었네요 ㅠㅠ enum 사용할수있도록 수정 하겠습니다~!
감사합니다 :)

private Long orderTableId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_table_id")
private OrderTable orderTable;
private String orderStatus;
Copy link
Member

Choose a reason for hiding this comment

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

enum을 사용하시는게 좋을것같아요!

Comment on lines +24 to +25
public ResponseEntity<MenuGroupResponse> create(@RequestBody final MenuGroupRequest request) {
final MenuGroupResponse created = menuGroupService.create(request);
Copy link
Member

Choose a reason for hiding this comment

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

request, response 로 리턴하시는거 좋네요 ㅎㅎ

Comment on lines +24 to +25
public ResponseEntity<MenuGroupResponse> create(@RequestBody final MenuGroupRequest request) {
final MenuGroupResponse created = menuGroupService.create(request);
Copy link
Member

Choose a reason for hiding this comment

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

경로는 RequestMapping으로 빼서 사용하시면 보다 깔끔할것같네요
전체적으로도 확인해보시면 좋을것같아요!

Copy link
Author

Choose a reason for hiding this comment

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

@RequestMapping을 통해 분리해보록 하겠습니다~!


class MenuTest {

@Test
Copy link
Member

Choose a reason for hiding this comment

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

여기엔 @DisplayName 이 빠져있네요!

Copy link
Author

Choose a reason for hiding this comment

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

실수로 빠뜨렸네요 ㅠㅠ 추가하도록 하겠습니다~!

@limwoobin
Copy link
Member

리팩토링 순서에 대해 고민하신 방법으로 진행하셧군요 ㅎㅎ 굉장히 좋은것같습니다
저같은 경우는 인수테스트의 보호를 기반으로 리팩토링을 진행했었는데요
리팩토링 대상 메소드에 대해 카피본을 추가로 생성한 이후
카피한 메소드에서 리팩토링을 진행하고 단위테스트, 인수테스트를 카피한 메소드가 동작하게끔 수정하여 정상동작하는지 검증했습니다.
이후 기존 메소드를 fadeout 하는 방식으로 진행했었어요
이렇게 리팩토링했을때 제가 느꼈던 장점은 기존 레거시를 안정적으로 보호할 수 있다는
점이 가장 컸던것 같습니다 :)

@Gyeom
Copy link
Author

Gyeom commented Dec 15, 2022

리뷰어님~ 안녕하세요

꼼꼼한 피드백 덕분에 많이 배울 수 있었습니다.
피드백 반영해서 리뷰 요청 드립니다~!

이번 리뷰도 잘 부탁드립니다 🙏 🙏 🙏

Copy link
Member

@limwoobin limwoobin left a comment

Choose a reason for hiding this comment

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

안녕하세요 대겸님
2단계 피드백 꼼꼼하게 잘 반영해주셨네요 👍👍
정말 코드량만큼 고생도 많으셧을거라 생각됩니다

몇가지 코멘트를 남겨드렷으니 다음미션 하면서 같이 확인해주심 좋을것같아요
그럼 2단계는 여기서 머지하겠습니다
고생많으셨습니다!

for (final Menu menu : menus) {
menu.setMenuProducts(menuProductDao.findAllByMenuId(menu.getId()));
}
private List<Product> toProduct(final List<MenuProductRequest> menuProductRequests) {
Copy link
Member

Choose a reason for hiding this comment

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

findProducts와 같은 이름은 어떨까요?
repository를 통해 조회하는것이라 더 알맞지 않을까 싶습니다 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

repository를 통해 조회하는것은 findXX 규칙 좋네요 ㅎㅎ
감사합니다~!

Comment on lines +58 to 61
Map<Long, Product> productIdToProduct = new HashMap<>();
for (Product product : products) {
productIdToProduct.put(product.getId(), product);
}
Copy link
Member

Choose a reason for hiding this comment

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

오 map으로 처리하셧군요 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

넵 복잡도가 N이 초과하지 않는 방법이 어떤게 있을까 고민하다가 방법이 잘 떠오르지 않아 map을 활용했습니다ㅠㅠ

Copy link
Member

Choose a reason for hiding this comment

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

저도 이런경우 map을 활용하고는 합니다
루프를 돌면서 찾기엔 복잡도가 너무올라가서요 ㅎㅎ

@@ -0,0 +1,36 @@
package kitchenpos.common;

public enum ErrorMessage {
Copy link
Member

Choose a reason for hiding this comment

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

예외메시지를 별도로 분리해 상수로 처리하셧네요 ㅎㅎ
보다 깔끔해진것같습니다!

Comment on lines +86 to +87
orderTable.unGroup();
orderTableRepository.save(orderTable);
Copy link
Member

Choose a reason for hiding this comment

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

이미 알고계신 내용일수도 있지만
@transactional 이 끝나면 더티체킹이 발생해 굳이 save를 선언하지 않아도
변경사항이 적용되게 됩니다 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

불필요한 로직이 있었네요~ 수정하도록 하겠습니다 ㅎㅎ 감사합니다!

Copy link
Member

Choose a reason for hiding this comment

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

명시하는것도 저는 괜찮다고 생각해요!

public enum OrderStatus {
COOKING, MEAL, COMPLETION
COOKING("조리"), MEAL("식사"), COMPLETION("계산완료");
Copy link
Member

Choose a reason for hiding this comment

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

피드백을 잘 반영해주셧네요 :)


jpa:
properties:
hibernate:
Copy link
Member

Choose a reason for hiding this comment

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

batch size 설정을 넣어주셔도 좋을것같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

이런 방법이 있었군요 ㅎㅎ 좋은 정보 감사합니다 👍

Comment on lines +26 to +28
public MenuGroup toEntity() {
return MenuGroup.of(name);
}
Copy link
Member

Choose a reason for hiding this comment

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

오 의존성 방향 좋네요 ㅎㅎ
다만 공통으로 쓰이는게 아니니 toEntity보다는 도메인에 대한 네이밍을 활용하는건 어떨지 제안드려봅니다
예를들면 toMenuGroup과 같이요 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

보다 의미가 명확해질 것 같아요 ㅎㅎㅎ 다른 도메인도 같이 변경하도록 하겠습니다~!

public class OrderResponse {
private Long id;
private final Long orderTableId;
@Enumerated(EnumType.STRING)
Copy link
Member

Choose a reason for hiding this comment

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

해당 어노테이션은 없어도 될것같아요 ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

아이고,, 제가 실수로 넣은 것 같습니다 ㅠㅠㅠ 수정하도록 할게요~! 감사합니다

@JoinColumn(name = "table_group_id")
private TableGroup tableGroup;
@JsonIgnore
@BatchSize(size = 5)
Copy link
Member

Choose a reason for hiding this comment

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

아 여기서 선언해주셧군요 ㅎㅎ
다른 OneToMany에서 동일하게 사용하시려면 yml파일에 작성하시는것도
고려해보심 좋습니다!

@limwoobin limwoobin merged commit aa07f83 into next-step:gyeom Dec 16, 2022
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.

None yet

2 participants