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] 인수 테스트 리팩터링 #184

Merged
merged 11 commits into from Jun 6, 2021
Merged

Conversation

LenKIM
Copy link

@LenKIM LenKIM commented Jun 5, 2021

안녕하세요. 리뷰어님! 2단계 리뷰 부탁드립니다.

코드를 잘 작성했는지 여부가 판단이 안되네요.

처음 고민했던 부분은 Section 을 어떤 기준으로 잡아야 하는지 고민이였습니다.
JPA 를 학습했지만, 활용할 때마다 늘 이렇게 할까, 저렇게 할까 고민하게 되네요.

또한, Line 에 여러 Station 을 등록할 경우 정렬을 어떤 기준으로 해야되나 고민입니다 : )

아마 3단계에서 그 문제를 해결해야 되는 것 같긴한데, 일단은 2단계 요구사항에 대해서 해결한 뒤 코드리뷰 요청드립니다.

좋은 주말 보내세요😆

Copy link

@wheejuni wheejuni left a comment

Choose a reason for hiding this comment

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

2단계 빠르게 진행해주시느라 대단히 수고 많으셨습니다. 💯
간단한 피드백 몇 개 남겨보았구요, 반영 혹은 추가 질문 부탁드리겠습니다.

Comment on lines 45 to 46
Station downStation = stationRepository.findById(request.getDownStationId()).orElseThrow(() -> new DataIntegrityViolationException("Not Fount downStationId" + request.getDownStationId()));
Station upStation = stationRepository.findById(request.getUpStationId()).orElseThrow(() -> new DataIntegrityViolationException("Not Fount downStationId" + request.getUpStationId()));
Copy link

Choose a reason for hiding this comment

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

동일한 로직이 두 번 중복됩니다. private 메소드로의 추출을 시도해볼만 하지 않을까요?
추출한다면 어디서부터 어디까지 추출하는 것이 좋을까요?

Copy link
Author

Choose a reason for hiding this comment

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

stationId 가 매개변수로 받는 메소드로 추출되어야 하지 않을까요? 하지만, 고민되는 건 StationSerivce layer 에서도 할 수 있지만, 아직은 필요하지 않을 것 같아요.
조금더 LineSerivce 가 비대해지면 고려해볼만한 부분이라고 판단됩니다 👍

return LineResponse.of(persistLine);
Station downStation = stationRepository.findById(request.getDownStationId()).orElseThrow(() -> new DataIntegrityViolationException("Not Fount downStationId" + request.getDownStationId()));
Station upStation = stationRepository.findById(request.getUpStationId()).orElseThrow(() -> new DataIntegrityViolationException("Not Fount downStationId" + request.getUpStationId()));
int distance = request.getDistance();
Copy link

Choose a reason for hiding this comment

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

굳이 별도의 지역변수를 두지 않아도 될 것 같고 Section 의 생성자 호출시에 바로 넘겨도 괜찮겠다는 생각입니다.

Copy link
Author

Choose a reason for hiding this comment

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

네 😁 코드 수정하겠습니다.


Line save = lineRepository.save(line);
List<Station> stations = save.getStations();
return LineResponse.of(save, stations);
Copy link

Choose a reason for hiding this comment

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

파라메터로 Line 하나만 넘어가도, 결국 stations 까지 얻을 수 있겠는데요?

Copy link
Author

Choose a reason for hiding this comment

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

그러네요; 코드 리팩토링이 잘 마무리되지 않은 부분인것같습니다 ㅎㅎ 꼼꼼히 코드봐주셔서 감사합니다.

private String color;

public Line() {
@Embedded
private Sections sections = Sections.of(new ArrayList<>());
Copy link

Choose a reason for hiding this comment

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

이미 List 객체까지 초기화가 되어있는, 아래와 같은 스태틱 메소드를 구성하면 어떨까요?

public static Sections empty()

Copy link
Author

Choose a reason for hiding this comment

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

@Embedded 를 사용할 경우, 널 객체 패턴을 조심해서 활용하는게 좋을 것 같더라구요.

JPA 매직이 static 객체를 가만두지 않더군요. 하핫; 많이 당해봐서 ... 좀 더 자세한 내용은 아래 링크 첨부드렸습니다.

https://jojoldu.tistory.com/559

Copy link

Choose a reason for hiding this comment

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

@LenKIM 네, 널 객체 패턴을 사용하시라는 말씀은 아니고 Sections.of() 안에서 new ArrayList<>(); 를 넣어주면 되지 않을까 해서요.

Copy link
Author

Choose a reason for hiding this comment

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

아 그렇군요😳 죄송합니다. 텍스트를 잘못이해했습니다 ㅎ
그럼에도 불구하고, 피드백 감사합니다 : )

public List<Station> getStations() {
return this.sections.getValues().stream()
.map(section -> Stream.of(section.getUpStation(), section.getDownStation()))
.flatMap(Stream::distinct)
Copy link

Choose a reason for hiding this comment

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

바로 .distinct() 호출하시는 방법은 잘 안 되었나요?

Copy link
Author

Choose a reason for hiding this comment

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

64 번째 라인을 살펴보시면, map을 통해서 Stream.of() 사용할 경우 Stream<Stream<Station>>으로 반환되서 distinct() 사용할 경우, Stream<Stream> 으로 반환될것입니다. 그러므로 distinct() 안될것입니다.


public List<Station> getStations() {
return this.sections.getValues().stream()
.map(section -> Stream.of(section.getUpStation(), section.getDownStation()))
Copy link

Choose a reason for hiding this comment

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

https://www.baeldung.com/java-merge-streams
두 스트림을 하나로 합치는 구현이 필요하다면 이런 방법을 생각해보시면 좋겠습니다.

Copy link
Author

Choose a reason for hiding this comment

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

merge() 라는 메소드도 있군요 ㅎㅎ 링크 공유해주셔서 감사합니다.

@LenKIM LenKIM requested a review from wheejuni June 6, 2021 08:01
Copy link

@wheejuni wheejuni left a comment

Choose a reason for hiding this comment

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

수고 많으셨습니다. 👍

@wheejuni wheejuni merged commit 594a363 into next-step:lenkim Jun 6, 2021
@LenKIM
Copy link
Author

LenKIM commented Jun 7, 2021

코드 리뷰 해주셔서 감사합니다. 3단계 진행하겠습니다

@LenKIM LenKIM deleted the step2 branch June 7, 2021 03:54
@LenKIM LenKIM restored the step2 branch July 4, 2021 21:08
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