Conversation
그룹이 영구 삭제될 때 해당 그룹과 연결된 채팅방도 함께 삭제되도록 합니다. 이를 통해 연결되지 않은 채팅방이 남는 것을 방지하고 데이터 일관성을 유지합니다. 그룹 채팅방을 찾을 수 없는 경우를 대비하여 GroupErrorCode를 추가합니다.
|
Caution Review failedThe pull request is closed. 개요모임 삭제 시 관련 채팅방도 함께 삭제되도록 개선합니다. 새로운 오류 코드를 추가하고, 그룹과 채팅방 간 관계를 설정한 후 삭제 서비스에서 채팅방 삭제 로직을 구현합니다. 변경 사항
시퀀스 다이어그램sequenceDiagram
actor User
participant DeleteService as GroupV2DeleteService
participant Repo as ChatRoomRepository
participant GroupRepo as GroupV2Repository
User->>DeleteService: deleteHard(groupId)
rect rgb(240, 248, 255)
Note over DeleteService: S3 이미지 처리
DeleteService->>DeleteService: S3 variant URLs 수집 및 삭제
end
rect rgb(240, 255, 240)
Note over DeleteService: 채팅방 삭제 (신규)
DeleteService->>Repo: findByGroupId(groupId)
alt 채팅방 없음
Repo-->>DeleteService: Optional.empty()
DeleteService->>DeleteService: ❌ GROUP_CHAT_ROOM_NOT_FOUND_BY_ID 예외 발생
else 채팅방 존재
Repo-->>DeleteService: ChatRoom
DeleteService->>Repo: deleteById(chatRoomId)
Repo-->>DeleteService: 삭제 완료
end
end
rect rgb(255, 250, 240)
Note over DeleteService: 그룹 정리
DeleteService->>GroupRepo: 그룹 사용자, 태그, 이미지, 그룹 삭제
GroupRepo-->>DeleteService: 삭제 완료
end
코드 리뷰 예상 난이도🎯 3 (중간) | ⏱️ ~20분 관련 PR
시 🐰
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR improves the group deletion feature by ensuring that when a group is permanently deleted, its associated chat room is also removed to maintain data consistency and prevent orphaned chat rooms.
Key Changes:
- Added
@OneToOnerelationship betweenGroupV2andChatRoomwith cascade deletion - Modified
GroupV2DeleteService.deleteHard()to explicitly handle chat room deletion - Added new error code
GROUP_CHAT_ROOM_NOT_FOUND_BY_IDfor missing chat room scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
GroupV2.java |
Added bidirectional @OneToOne relationship with ChatRoom using cascade and orphan removal |
GroupV2DeleteService.java |
Added chat room lookup and explicit deletion before group removal |
GroupErrorCode.java |
Added new error code for handling missing group chat rooms |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // chat room 확인 | ||
| ChatRoom chatRoom = chatRoomRepository.findByGroupId(groupId) | ||
| .orElseThrow( | ||
| () -> new GroupException(GroupErrorCode.GROUP_CHAT_ROOM_NOT_FOUND_BY_ID, | ||
| groupId)); | ||
|
|
||
| // DB 삭제 | ||
| chatRoomRepository.deleteById(chatRoom.getId()); |
There was a problem hiding this comment.
The explicit deletion of the chat room using chatRoomRepository.deleteById(chatRoom.getId()) is unnecessary because the GroupV2 entity now has a @OneToOne relationship with ChatRoom configured with cascade = CascadeType.ALL and orphanRemoval = true. When groupV2Repository.delete(group) is called on line 79, the associated chat room will be automatically deleted due to these cascade settings.
Additionally, throwing an exception when the chat room is not found may be too strict. Consider using ifPresent to handle cases where a group might not have an associated chat room, or logging a warning instead of failing the entire group deletion operation.
| @OneToMany(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<GroupUserV2> users = new ArrayList<>(); | ||
|
|
||
| @OneToOne(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true) |
There was a problem hiding this comment.
The @OneToOne relationship with cascade = CascadeType.ALL and orphanRemoval = true is correctly configured on the non-owning side (mappedBy = "group"). However, this configuration means that when a GroupV2 entity is deleted, the associated ChatRoom will be automatically removed. Ensure that this cascading behavior is intentional and that the corresponding relationship on the ChatRoom side does not have cascade settings that could create circular dependencies or unexpected deletion behavior.
| @OneToOne(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true) | |
| @OneToOne(mappedBy = "group") |
📝 Pull Request
📌 PR 종류
해당하는 항목에 체크해주세요.
✨ 변경 내용
그룹이 영구 삭제될 때 해당 그룹과 연결된 채팅방도 함께 삭제되도록 합니다.
이를 통해 연결되지 않은 채팅방이 남는 것을 방지하고 데이터 일관성을 유지합니다.
그룹 채팅방을 찾을 수 없는 경우를 대비하여 GroupErrorCode를 추가합니다.
🔍 관련 이슈
🧪 테스트
변경된 기능에 대한 테스트 범위 또는 테스트 결과를 작성해주세요.
🚨 확인해야 할 사항 (Checklist)
PR을 제출하기 전에 아래 항목들을 확인해주세요.
🙋 기타 참고 사항
리뷰어가 참고하면 좋을 만한 추가 설명이 있다면 적어주세요.
Summary by CodeRabbit
버그 수정
✏️ Tip: You can customize this high-level summary in your review settings.