-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Route의 dateSchedule 필드를 설정하지 않음 #313
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,49 +53,56 @@ public class DateSchedFacade { | |||||||
|
|
||||||||
| @Transactional | ||||||||
| public void createDateSchedule(User user, DateSchedCreateRequest request) { | ||||||||
| // 1. Place 목록 준비 (조회 또는 생성) | ||||||||
| List<Place> places = request.getPlaces().stream() | ||||||||
| .map(placeDto -> getOrCreatePlace(user, placeDto)) | ||||||||
| .toList(); | ||||||||
|
|
||||||||
| // 2. DateSchedule 생성 | ||||||||
| DateSchedule dateSchedule = DateSchedule.builder() | ||||||||
| .name(request.getName()) | ||||||||
| .scheduleAt(LocalDate.parse(request.getScheduleAt())) | ||||||||
| .user(user) | ||||||||
| .build(); | ||||||||
| dateSchedService.save(dateSchedule); | ||||||||
|
|
||||||||
| // 3. Route 생성 (DateSchedule 참조) | ||||||||
| Route route = Route.builder() | ||||||||
| .name(request.getName()) | ||||||||
| .status(RouteStatus.WRITE) | ||||||||
| .createdBy(user) | ||||||||
| .routeType(request.getPlaces().size() == 1 ? RouteType.PLACE : RouteType.COURSE) | ||||||||
| .routeType(places.size() == 1 ? RouteType.PLACE : RouteType.COURSE) | ||||||||
| .dateSchedule(dateSchedule) | ||||||||
| .build(); | ||||||||
| routeService.saveRoute(route); | ||||||||
|
||||||||
| routeService.saveRoute(route); | |
| routeService.saveRoute(route); | |
| route.updateDateSchedule(dateSchedule); |
Copilot
AI
Jan 12, 2026
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.
The refactored createDateSchedule method lacks test coverage. While there is a commented-out test in DateScheduleControllerTest, the method's business logic - particularly the new entity creation order, bidirectional relationship handling, and the extracted getOrCreatePlace helper method - should be covered by unit or integration tests to prevent regressions.
Copilot
AI
Jan 12, 2026
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.
Potential uncaught 'java.lang.NumberFormatException'.
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.
위도와 경도 값을 String에서 Double로 변환할 때 Double.valueOf()를 직접 사용하면, 유효하지 않은 숫자 형식의 문자열이 들어올 경우 NumberFormatException이 발생하여 500 에러로 이어질 수 있습니다. validatePlace 메서드에서 이 값들의 형식을 검증하는 로직이 없다면, DTO 레벨에서 @Pattern과 같은 유효성 검사 어노테이션을 추가하거나, 이 메서드 내에서 try-catch 블록으로 예외를 처리하여 적절한 비즈니스 예외(예: 400 Bad Request)를 던지는 것을 고려해보세요.
Copilot
AI
Jan 12, 2026
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.
Potential uncaught 'java.lang.NumberFormatException'.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,10 @@ public void updateStatus(RouteStatus routeStatus) { | |
| this.status = routeStatus; | ||
| } | ||
|
|
||
| public void updateDateSchedule(DateSchedule dateSchedule) { | ||
| this.dateSchedule = dateSchedule; | ||
| } | ||
|
Comment on lines
+79
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 양방향 연관관계를 설정할 때는 연관관계의 양쪽 모두를 업데이트하여 객체 상태의 일관성을 유지하는 것이 중요합니다. 현재 일관성을 유지하기 위해 이 메서드 내에서 |
||
|
|
||
| /** | ||
| * 새로운 Route 생성 | ||
| */ | ||
|
|
||
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.
현재 로직은 데이터베이스 영속성 관점에서는 올바르게 동작하지만, 양방향 연관관계가 설정된 객체의 상태 일관성을 해칠 수 있는 잠재적인 위험이 있습니다.
dateSchedule과route객체를 각각 생성하고 저장한 후에,route객체에는dateSchedule을 설정했지만,dateSchedule객체의route필드는 설정되지 않은 상태로 남아있게 됩니다. 이로 인해 해당 트랜잭션 내에서dateSchedule.getRoute()를 호출하면null이 반환되어 예상치 못한 동작을 유발할 수 있습니다.양방향 연관관계에서는 연관관계의 양쪽 모두를 설정해주는 것이 좋습니다.
DateSchedule엔티티에Route를 설정하는 편의 메서드(예:setRoute(Route route))를 추가하고,route생성 후 이를 호출하여 객체 그래프의 일관성을 유지하는 것을 고려해보세요.