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단계] 다니(이다은) 미션 제출합니다. #193

Merged
merged 29 commits into from
Nov 24, 2021

Conversation

da-nyee
Copy link

@da-nyee da-nyee commented Nov 24, 2021

오랜만이에요 에어 ~!
좀 더 빨리 제출하고 싶었는데,, 생각보다 오래 걸렸네요 🥲

2단계는 아래와 같이 진행했습니다 !

  • setter를 생성자로 변경
  • DAO를 JPA로 변경
  • Entity를 DTO로 변경
  • 비즈니스 로직을 도메인으로 이동

지금 changeEmpty()와 관련된 테스트가 각각 실행하면 통과하나, 전체로 실행하면 실패해요 😥
아직 이유를 못 찾고 있는데, 먼저 제출하고 더 알아볼게요!
혹시,, 이번에도 함께 고민해줄 수 있을까요 ㅎㅎㅎㅎ

1단계에서 정성어린 리뷰들 달아줘서 정말 고마웠습니다 !!
이번에도 잘 부탁드립니다 🙇‍♀️✨

@da-nyee da-nyee requested a review from KJunseo November 24, 2021 17:55
Copy link

@KJunseo KJunseo left a comment

Choose a reason for hiding this comment

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

안녕하세요 다니~ 리팩터링 잘 해주셨네요! 👍🏻👍🏻👍🏻
리뷰하면서 저도 공부가 되네요!
몇 가지 궁금한 점과 제안을 코멘트로 남겼어요! 확인해보시고 반영하시거나 코멘트 달아주시면 감사하겠습니다!
step2는 머지하겠습니다! 피드백 반영은 다음 단계 때 같이 해주세요!
고생 많으셨고 진짜 얼마 안 남았는데 마지막까지 화이팅! 😄

Comment on lines +81 to +82
Long quantity = menuProduct.getQuantity();
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
Copy link

Choose a reason for hiding this comment

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

MenuProduct의 금액 계산시 MenuProduct에서 quantity를 가져와서 계산하지 않고, MenuProduct에 메세지를 보내는 건 어떻게 생각하시나요?


public Long getId() {
return id;
private Long numberOfGuests;
Copy link

Choose a reason for hiding this comment

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

이 부분을 Long으로 바꾸신 이유가 있을까요?? clone을 받아 실행시켜보려고 했는데 이 부분에서 문제가 있어서 실행이 안되는 것 같네요ㅠㅠ

Comment on lines +70 to +71
Orders orders = ordersRepository.findById(requestDto.getOrderTableId())
.orElseThrow(IllegalArgumentException::new);
Copy link

Choose a reason for hiding this comment

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

Order을 조회하는데 OrderTableId를 사용해서 조회하고 있어요!
해당 Table의 모든 Order을 검증하기 위해서는 List 형태로 가져와야 할 것 같아요!

OrderTable 내부에서 List를 객체 참조해도 될 것 같고, 그게 아니라면 orderTableId로 findAllByOrderTable_Id()로 가져와야 할 것 같아요.

Comment on lines +72 to 75
String orderStatus = orders.getOrderStatus();
if (COOKING.name().equals(orderStatus) || MEAL.name().equals(orderStatus)) {
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.

이 로직도 도메인에서 처리할 수 있지 않을까요?


return orderTableDao.save(savedOrderTable);
entityManager.flush();
Copy link

Choose a reason for hiding this comment

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

EntityManager을 주입받아서 flush 해주신 이유가 있을까요? 이 메서드 말고 전체적으로 EntityManager을 주입받아 사용하신 부분이 있던데 이유가 궁금하네요!

Comment on lines +80 to 87
List<OrderTable> orderTables = tableRepository
.findAllByTableGroupId(requestDto.getId());

if (ordersRepository.existsByOrderTableInAndOrderStatusIn(
orderTables,
Arrays.asList(COOKING.name(), MEAL.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.

TableGroup에서 List를 참조하고 있어서 TableGroup 조회시 연관된 OrderTable도 가져와질 것 같은데 따로 repository에서 가져오신 이유가 있을까요??

검증도 TableGroup 내에서 메세지를 보내는 식으로 처리할 수도 있을 것 같네요!

public TableEmptyResponseDto changeEmpty(TableEmptyRequestDto requestDto) {
OrderTable orderTable = tableRepository.findById(requestDto.getOrderTableId())
.orElseThrow(IllegalArgumentException::new);
if (Objects.nonNull(orderTable.getTableGroup())) {
Copy link

Choose a reason for hiding this comment

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

OrderTable 내부에서 검증해도 되겠네요!

import kitchenpos.application.dto.response.MenuResponseDto;
import kitchenpos.domain.Menu;

public class MenuDtoAssembler {
Copy link

Choose a reason for hiding this comment

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

Dto -> 도메인이나, 도메인 -> Dto 변환시 전반적으로 Assembler 클래스를 만드셔서 사용하신 걸 봤어요!
혹시 이렇게 따로 클래스를 만들어 사용하신 이유가 있을까요? 처음 보는 방식이라서 어떤 점 때문에 이 방식을 사용하게 되셨는지 궁금해요! 😄

@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String orderStatus;
Copy link

Choose a reason for hiding this comment

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

이 부분도 @Enumerated를 적용해 보는 건 어떨까요??

@@ -8,7 +8,7 @@ CREATE TABLE orders (

CREATE TABLE order_line_item (
seq BIGINT(20) NOT NULL AUTO_INCREMENT,
order_id BIGINT(20) NOT NULL,
orders_id BIGINT(20),
Copy link

Choose a reason for hiding this comment

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

이 부분이랑 menu_product의 menu_id 부분의 NOT NULL을 제거하신 이유가 있나요??

@KJunseo
Copy link

KJunseo commented Nov 24, 2021

지금 changeEmpty()와 관련된 테스트가 각각 실행하면 통과하나, 전체로 실행하면 실패해요 😥
아직 이유를 못 찾고 있는데, 먼저 제출하고 더 알아볼게요!
혹시,, 이번에도 함께 고민해줄 수 있을까요 ㅎㅎㅎㅎ

  1. TableServiceIntegrationTest#changeEmpty_Valid_Success() 부분이 실패하는 경우는 changeEmpty() 로직을 수정하니까 성공하는 것을 확인했어요!(관련 코멘트)

  2. TableGroupServiceIntegrationTest#ungroup_CookingOrderStatus_Fail()TableGroupServiceIntegrationTest#ungroup_MealOrderStatus_Fail() 같은 경우는 Auto Increment 때문이라는 생각이 들어요.
    @transactional은 롤백은 되지만 Auto Increment까지 초기화를 시켜주지는 않아서 전체 테스트 때 문제가 발생하는 것 같아요.

각각 실행했을 때(OrdersService#changeOrderStatus())

스크린샷 2021-11-25 오전 5 28 46

전체로 실행했을 때(OrdersService#changeOrderStatus())

스크린샷 2021-11-25 오전 5 29 32

@KJunseo KJunseo merged commit f59e3ff into woowacourse:da-nyee Nov 24, 2021
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