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

3단계 - 지하철 구간 관리 #284

Merged
merged 19 commits into from
Feb 2, 2022
Merged

Conversation

DaehunGwak
Copy link

모르는게 많아 오래걸렸지만
3단계 완료 지금되어 PR 드립니다!

Copy link

@junwoochoi junwoochoi left a comment

Choose a reason for hiding this comment

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

안녕하세요!
3단계 테스트 코드가 정말 깔끔하네요 👍 👍
몇가지 추가로 고민해볼만한 부분 관련해서 코멘트 달아보았는데 확인해주시기 바랍니다!
즐거운 설명절되세요!!

Comment on lines 33 to 34
Section section = new Section(upStation, downStation, request.getDistance());
line.addSection(section);

Choose a reason for hiding this comment

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

Section의 생성자의 책임을 Line객체 내부로 옮겨보면 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

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

확실히 Line에 의존적이니 해당 책임을 Line 으로 위임하는 것이 더 바람직하겠네요 수정하겠습니다 :)

Comment on lines 53 to 55
downStation = stationRepository.findById(downStationId)
.orElseThrow(() -> new IllegalArgumentException(
"노선의 구간 초기화 중 하행선역을 찾을 수 없습니다. downStationId:" + downStationId));

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.

아래 코멘트와 같은 선에서 LineService에서 전반적으로 private메서도르 줄여볼 수 있겠네요 감사합니다 :)


@Service
@Transactional
public class SectionService {

Choose a reason for hiding this comment

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

Section객체는 Line과 같은 라이프사이클을 공유하고 있어서, LineService에서 모두 관리하면 중복 코드가 많이 제거될 수 있지 않을까요?

Comment on lines 23 to 24
@OneToMany(mappedBy = "line", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
private List<Section> sections = new ArrayList<>();

Choose a reason for hiding this comment

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

@Embedded 혹은 @Embeddable 어노테이션을 활용해서 응집도 높은 객체를 만들어보면 어떨까요? 👀

Copy link
Author

Choose a reason for hiding this comment

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

JPA 에서 일급컬렉션같이 활용하는 부분을 고민했었는데 임베딩할 수가 있었군요!
공유 감사합니다 :) 해당 방향으로 수정해보겠습니다.

Comment on lines 10 to 15
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private Line line;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private Station upStation;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private Station downStation;

Choose a reason for hiding this comment

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

cascade의 범위를 잘 고민해보면 더 좋을 것 같아요!

Copy link
Author

Choose a reason for hiding this comment

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

CascadeType에 대해 더 공부를 해봐야겠네요!
공유 감사합니다 :)

Comment on lines +19 to +25
LineTestRequest lineTestRequest = LineTestStep.지하철_노선_요청_신분당선_데이터_생성하기();

// when
ExtractableResponse<Response> response = LineTestStep.지하철_노선을_생성한다(color, name);
ExtractableResponse<Response> response = LineTestStep.지하철_노선을_생성한다(lineTestRequest);

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED.value());
assertThat(response.header("Location")).isNotBlank();
Integer responseIntegerId = response.jsonPath().get("id");
Long createdId = responseIntegerId.longValue();
assertThat(createdId).isGreaterThan(0L);
LineTestStep.지하철_노선_생성_성공_검증하기(response);

Choose a reason for hiding this comment

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

given when then 스탭이 간결하고, 한눈에 들어오네요! 💯

@Test
void createSection() {
// given
LineTestRequest lineRequest = LineTestStep.지하철_노선_요청_신분당선_데이터_생성하기();

Choose a reason for hiding this comment

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

클래스내 메소드들이 반복적인 샘플케이스를 만드는 경우 field 변수를 만들고 beforeEach에서 할당해주는 것도 하나의 방법입니다 :)

Copy link

@junwoochoi junwoochoi left a comment

Choose a reason for hiding this comment

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

안녕하세요! 1주차 미션 모두 머지 하도록 하겠습니다!
다음 주차도 화이팅 입니다!! 🚀

@@ -30,8 +30,7 @@ public LineResponse saveLine(LineRequest request) {

Line line = new Line(request.getName(), request.getColor());
if (Objects.nonNull(upStation) && Objects.nonNull(downStation)) {
Section section = new Section(upStation, downStation, request.getDistance());
line.addSection(section);
line.addSection(upStation, downStation, request.getDistance());

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
super.setUp();
lineRequest = LineTestStep.지하철_노선_요청_신분당선_데이터_생성하기();
lineId = LineTestStep.지하철_노선_생성한_후_아이디_추출하기(lineRequest);

Choose a reason for hiding this comment

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

💯

Comment on lines +15 to +16
@Embeddable
public class Sections {

Choose a reason for hiding this comment

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

Sections 내부에 도메인 로직이 응집되서 유지보수가 더 용이해졌을 것 같네요 👍


@Embeddable
public class Sections {
public static final int MIN_SECTION_SIZE = 1;

Choose a reason for hiding this comment

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

매직넘버 분리 💯

Station upStation = findStationById(request.getUpStationId());
Station downStation = findStationById(request.getDownStationId());

Section addedSection = line.addSection(upStation, downStation, request.getDistance());

Choose a reason for hiding this comment

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

현재는 section을 추가하는 책임과 해당 section을 리턴하는 책임 모두 가지고 있어서, 두 메소드로 분리해서 호출해 사용하면 더 가독성이 좋을 것 같습니다 :)

@junwoochoi junwoochoi merged commit b3e4da7 into next-step:daehungwak Feb 2, 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