[레거시 코드 리팩토링 - 2단계] 케빈(박진홍) 미션 제출합니다.#109
Conversation
bosl95
left a comment
There was a problem hiding this comment.
안녕하세요 케빈!!!! 💪
꼼꼼한 코드 정말 잘 보았습니다!!!!!! 엔티티가 많고 복잡한 부분도 있었는데, 코드를 워낙 잘 작성해주셔서 읽는 데 크게 불편함을 못 느꼈네요 👍👍👍 많이 배워갑니다 !
크게 수정할 필요가 있다고 느껴진 부분은 없었구요!
작성해주신 코드에 대한 생각이 궁금해 몇자 코멘트 남겨보았어요! 보시고 다시 요청 보내주세요!!
| this.menuGroupDao = menuGroupDao; | ||
| private final MenuGroupRepository menuGroupRepository; | ||
|
|
||
| public MenuGroupService(MenuGroupRepository menuGroupRepository) { |
There was a problem hiding this comment.
코드들 보면 보통 인자에 final이 붙어있던데, 이 친구만 final이 없는 이유가 있을까요???
There was a problem hiding this comment.
앗 사실 저는 인스턴스 필드를 제외한 파라미터 부분이나 지역변수에는 final 키워드 작성을 선호하지 않는데요. (너무 길어져서)
초기에 제공된 기본 코드는 final이 전부 붙어있었는데 리팩터링하면서 일부분을 지웠나봅니다~
| private MenuGroupResponse convert(MenuGroupResponseDto menuGroupResponseDto) { | ||
| return new MenuGroupResponse(menuGroupResponseDto.getId(), menuGroupResponseDto.getName()); |
There was a problem hiding this comment.
저는 컨트롤러에 이런 변환 로직이 많이 들어가는 걸 선호하지 않아서 menuGroupResponseDto.ToXXX()이런 식으로 DTO 내부에서 처리해주기도 해요! 케빈도 이미 아실 거 같긴 한데 어떠한 이유로 이렇게 작성해주셨을까요?!
There was a problem hiding this comment.
메서드가 있었는데 깜빡하고 저걸 그대로 쓰고있었네요 ㅎㅎㅎ;;
| List<OrderTable> orderTables = tableGroupRequestDto.getOrderTables() | ||
| .stream() | ||
| .map(orderTable -> convert(orderTable.getId(), tableGroup)) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
이 부분도 DTO에게 List로 변환해서 반환해주도록 하면 서비스 레이어의 로직을 좀 더 작게 가져갈 수 있지 않을까 하는 생각입니다! 케빈은 어떻게 생각하시나요??
There was a problem hiding this comment.
음 이부분은 convert를 보니
특정 그룹으로의 연관관계 맵핑 등의 로직이 있어서 서비스 레이어가 적합하다고 생각해서 두었습니다!
|
|
||
| public static TableGroupResponse from(TableGroupResponseDto tableGroupResponseDto) { | ||
| if (Objects.isNull(tableGroupResponseDto)) { | ||
| return null; |
There was a problem hiding this comment.
궁금한 점이 있습니다!!
여기서 Null이 반환되면 이 이 TableGroupResponse의 null excpetion이 발생하는 곳은 어디일까요??? get()하기 전까지 이 Null을 계속 안고 가는 걸까요??
그리고 TableGroupResponse가 null인 이유는 TableGroupResponseDTO가 null이여서 일텐데, 만약 TableGroupResponse을 get으로 호출하다 null 예외가 발생할 경우 TableGroupResponseDTO가 null이기때문이라는 것을 파악하기 쉽지 않을 거 같아보였어요!
어떻게 생각하시나요!!
There was a problem hiding this comment.
OrderTable과 TableGroup은 N:1 관계인데요. nullable = true입니다.
이같이 처음 OrderTable을 생성하는 경우 그 응답으로 OrderTableResponse(혹은 DTO)를 생성할 때 OrderTableResponse 내부에
이렇게 TableGroupResponse도 작성하는 로직이 있는데요.
tableGroup이 null일때 해당 코드가 없으면 npe가 발생합니다.
지금 제공된 API 스펙의 응답이 정해진게없어서 Response를 공통으로 쓰다보니 저런 분기가 조금 생긴것같은데요 ㅠㅠ
tradeoff라 생각됩니다..
|
|
||
| import java.util.List; | ||
|
|
||
| @Transactional(readOnly = true) |
There was a problem hiding this comment.
케빈 코드 볼때마다 느끼는 거지만 정말 꼼꼼하신 게 느껴집니다 👍 멋지네요!!
| public static MenuGroupResponse from(MenuGroupResponseDto menuGroupResponseDto) { | ||
| return new MenuGroupResponse(menuGroupResponseDto.getId(), menuGroupResponseDto.getName()); | ||
| } | ||
|
|
There was a problem hiding this comment.
오 ... 앞에서 제가 toXXX()로 변환에 대해 언급한 부분이 딱 이런 느낌일 거 같은데, 변환 로직을 dto에서 작성하시고 안하시는 기준이 있으신 걸까요?????/
There was a problem hiding this comment.
으음 전달해야할 인자가 3개 이상 많다고 느껴지는 경우는 별도로 분리하고 그 밑은 그냥 두는 편인데요.
지금보니 하나로 통일해주는게 좋을것같네요 :)
There was a problem hiding this comment.
지금보니 메서드를 만들어놨는데 제가 안쓰고 있었네요... ㅋㅋ ㅠㅠ
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| @DisplayName("Menu 엔티티 단위 테스트") |
| @ParameterizedTest | ||
| @ValueSource(ints = {-2, -1}) |
There was a problem hiding this comment.
Junit 배운 이후로 레벨 2 정도까지 쓰다가 잘 안 쓰게 되었는데, 케빈 코드 보면서 이런 것도 배웠었지 했습니다 ㅎㅎ 활용도 정말 잘하시네요 ㅎㅎ



안녕하세요 포모~
2단계 미션은 다음과 같이 진행했습니다.
Service Layer에 산재한 비즈니스 로직들을 Domain으로 이동
DTO 생성
도메인 단위 테스트 추가