-
Notifications
You must be signed in to change notification settings - Fork 284
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
3단계 - 지하철 구간 관리 #284
Conversation
- 테스팅용 DTO LineTestRequest 를 추가 - 위 클래스 관련된 LineTestStep, LineAcceptanceTest 부분 수정
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요!
3단계 테스트 코드가 정말 깔끔하네요 👍 👍
몇가지 추가로 고민해볼만한 부분 관련해서 코멘트 달아보았는데 확인해주시기 바랍니다!
즐거운 설명절되세요!!
Section section = new Section(upStation, downStation, request.getDistance()); | ||
line.addSection(section); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Section의 생성자의 책임을 Line객체 내부로 옮겨보면 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확실히 Line에 의존적이니 해당 책임을 Line 으로 위임하는 것이 더 바람직하겠네요 수정하겠습니다 :)
downStation = stationRepository.findById(downStationId) | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
"노선의 구간 초기화 중 하행선역을 찾을 수 없습니다. downStationId:" + downStationId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복되는 코드를 줄여볼 수 있을까요?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Section객체는 Line과 같은 라이프사이클을 공유하고 있어서, LineService에서 모두 관리하면 중복 코드가 많이 제거될 수 있지 않을까요?
@OneToMany(mappedBy = "line", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true) | ||
private List<Section> sections = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Embedded
혹은 @Embeddable
어노테이션을 활용해서 응집도 높은 객체를 만들어보면 어떨까요? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JPA 에서 일급컬렉션같이 활용하는 부분을 고민했었는데 임베딩할 수가 있었군요!
공유 감사합니다 :) 해당 방향으로 수정해보겠습니다.
@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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cascade의 범위를 잘 고민해보면 더 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CascadeType에 대해 더 공부를 해봐야겠네요!
공유 감사합니다 :)
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); |
There was a problem hiding this comment.
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.지하철_노선_요청_신분당선_데이터_생성하기(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스내 메소드들이 반복적인 샘플케이스를 만드는 경우 field 변수를 만들고 beforeEach에서 할당해주는 것도 하나의 방법입니다 :)
- 영속성 전이: 부모의 연관관계를 가지 자식을 함께 저장하고 싶을 때 사용 - 내가 사용하는 Section은 이미 Line을 주체로 작성 된 상태 - 따라서, Section에서는 자식 엔티티들을 관리하고 있는 상태가 아니므로 CascadeType.PERSIST를 사용할 필요가 없음
There was a problem hiding this 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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍
super.setUp(); | ||
lineRequest = LineTestStep.지하철_노선_요청_신분당선_데이터_생성하기(); | ||
lineId = LineTestStep.지하철_노선_생성한_후_아이디_추출하기(lineRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@Embeddable | ||
public class Sections { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 section을 추가하는 책임과 해당 section을 리턴하는 책임 모두 가지고 있어서, 두 메소드로 분리해서 호출해 사용하면 더 가독성이 좋을 것 같습니다 :)
모르는게 많아 오래걸렸지만
3단계 완료 지금되어 PR 드립니다!