Skip to content

Comments

[FEAT] 모임 삭제 개선#183

Merged
LimdaeIl merged 1 commit intomainfrom
feat/delete
Dec 30, 2025
Merged

[FEAT] 모임 삭제 개선#183
LimdaeIl merged 1 commit intomainfrom
feat/delete

Conversation

@LimdaeIl
Copy link
Collaborator

@LimdaeIl LimdaeIl commented Dec 30, 2025

📝 Pull Request

📌 PR 종류

해당하는 항목에 체크해주세요.

  • 기능 추가 (Feature)
  • 버그 수정 (Fix)
  • 문서 수정 (Docs)
  • 코드 리팩터링 (Refactor)
  • 테스트 추가 (Test)
  • 기타 변경 (Chore)

✨ 변경 내용

그룹이 영구 삭제될 때 해당 그룹과 연결된 채팅방도 함께 삭제되도록 합니다.

이를 통해 연결되지 않은 채팅방이 남는 것을 방지하고 데이터 일관성을 유지합니다.

그룹 채팅방을 찾을 수 없는 경우를 대비하여 GroupErrorCode를 추가합니다.

🔍 관련 이슈

🧪 테스트

변경된 기능에 대한 테스트 범위 또는 테스트 결과를 작성해주세요.

  • 유닛 테스트 추가 / 수정
  • 통합 테스트 검증
  • 수동 테스트 완료

🚨 확인해야 할 사항 (Checklist)

PR을 제출하기 전에 아래 항목들을 확인해주세요.

  • 코드 포매팅 완료
  • 불필요한 파일/코드 제거
  • 로직 검증 완료
  • 프로젝트 빌드 성공
  • 린트/정적 분석 통과 (해당 시)

🙋 기타 참고 사항

리뷰어가 참고하면 좋을 만한 추가 설명이 있다면 적어주세요.

Summary by CodeRabbit

버그 수정

  • 모임을 완전히 삭제할 때 해당 모임의 채팅방도 함께 올바르게 정리됩니다.
  • 모임 채팅방을 찾을 수 없는 경우에 대한 오류 처리가 추가되어 사용자 경험이 개선되었습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

그룹이 영구 삭제될 때 해당 그룹과 연결된 채팅방도 함께 삭제되도록 합니다.

이를 통해 연결되지 않은 채팅방이 남는 것을 방지하고 데이터 일관성을 유지합니다.

그룹 채팅방을 찾을 수 없는 경우를 대비하여 GroupErrorCode를 추가합니다.
@LimdaeIl LimdaeIl self-assigned this Dec 30, 2025
Copilot AI review requested due to automatic review settings December 30, 2025 06:20
@LimdaeIl LimdaeIl added the ✨enhancement New feature or request label Dec 30, 2025
@LimdaeIl LimdaeIl moved this from Backlog to In progress in WeGo-Together Backend Dec 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Caution

Review failed

The pull request is closed.

개요

모임 삭제 시 관련 채팅방도 함께 삭제되도록 개선합니다. 새로운 오류 코드를 추가하고, 그룹과 채팅방 간 관계를 설정한 후 삭제 서비스에서 채팅방 삭제 로직을 구현합니다.

변경 사항

응집력 / 파일 변경 요약
오류 처리
src/main/java/team/wego/wegobackend/group/domain/exception/GroupErrorCode.java
새로운 enum 상수 GROUP_CHAT_ROOM_NOT_FOUND_BY_ID 추가 (HTTP 404, 메시지: "모임: 모임 채팅방을 찾을 수 없습니다. 모임 ID: %s")
도메인 엔티티
src/main/java/team/wego/wegobackend/group/v2/domain/entity/GroupV2.java
GroupV2에서 ChatRoom으로의 양방향 일대일 관계 추가, mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true 적용
서비스 로직
src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2DeleteService.java
ChatRoom 및 ChatRoomRepository 임포트 추가, deleteHard 메서드에서 groupId로 ChatRoom 조회 후 예외 처리 및 채팅방 삭제 로직 구현

시퀀스 다이어그램

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
Loading

코드 리뷰 예상 난이도

🎯 3 (중간) | ⏱️ ~20분

관련 PR

  • PR #114: 같은 GroupErrorCode enum 클래스를 수정하여 새로운 오류 상수를 추가하는 작업
  • PR #176: 그룹의 자동 완전 삭제 흐름을 구현하는 작업으로, 해당 PR와 삭제 워크플로우가 겹치는 영역이 있음

시 🐰

채팅방이여 안녕을 해야지,
모임 함께 사라지네 🎪
고아 제거와 카스케이드로
깔끔한 삭제를 완성하고,
404 오류로 든든하게!

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd7ab06 and 615423f.

📒 Files selected for processing (3)
  • src/main/java/team/wego/wegobackend/group/domain/exception/GroupErrorCode.java
  • src/main/java/team/wego/wegobackend/group/v2/application/service/GroupV2DeleteService.java
  • src/main/java/team/wego/wegobackend/group/v2/domain/entity/GroupV2.java

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@LimdaeIl LimdaeIl merged commit e3721c0 into main Dec 30, 2025
4 of 5 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in WeGo-Together Backend Dec 30, 2025
@LimdaeIl LimdaeIl deleted the feat/delete branch December 30, 2025 06:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 @OneToOne relationship between GroupV2 and ChatRoom with cascade deletion
  • Modified GroupV2DeleteService.deleteHard() to explicitly handle chat room deletion
  • Added new error code GROUP_CHAT_ROOM_NOT_FOUND_BY_ID for 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.

Comment on lines +67 to +74
// chat room 확인
ChatRoom chatRoom = chatRoomRepository.findByGroupId(groupId)
.orElseThrow(
() -> new GroupException(GroupErrorCode.GROUP_CHAT_ROOM_NOT_FOUND_BY_ID,
groupId));

// DB 삭제
chatRoomRepository.deleteById(chatRoom.getId());
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@OneToMany(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true)
private List<GroupUserV2> users = new ArrayList<>();

@OneToOne(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true)
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
@OneToOne(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToOne(mappedBy = "group")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEAT] 모임 삭제 개선

1 participant