Skip to content

[Refactor] Cascade 연관 오류 - #158

Merged
chunny-k merged 1 commit into
mainfrom
develop
Feb 12, 2026
Merged

[Refactor] Cascade 연관 오류#158
chunny-k merged 1 commit into
mainfrom
develop

Conversation

@chunny-k

@chunny-k chunny-k commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

#️⃣연관된 이슈

ex) #이슈번호, #이슈번호

📝작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

스크린샷 (선택)

💬리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

Summary by CodeRabbit

  • Improvements
    • Enhanced account withdrawal process with proper cleanup of associated family profiles and wish list data.
    • Corrected wish count tracking when removing member profiles from family groups.
    • Improved data integrity during member account deletion.

@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request refactors member and family profile entity relationships by establishing bidirectional synchronization between Member and FamilyMemberProfile, adding wish list management repositories, and introducing a new withdrawal service that handles cascading profile deletion with associated wish count cleanup.

Changes

Cohort / File(s) Summary
Entity Relationship Setup
FamilyMemberProfile.java, Member.java
Added bidirectional synchronization through setMembers() and setFamilyMemberProfiles() helper methods. Added one-to-one relationship from Member to FamilyMemberProfile and one-to-many relationship from Member to Notification with cascade and orphanRemoval settings.
Repository Query Enhancements
MemberWishListRepository.java, MemberTransformedRecipeWishRepository.java
Added new finder method findMemberWishListsByFamilyMemberProfile_Id() with EntityGraph annotation for eager loading of related Recipe entities in both repositories. Updated decreaseWishCount logic to operate on TransformedRecipe in the transformed recipe wish repository.
Service Layer
FamilyMemberProfileService.java
Integrated wish list repositories as dependencies. Enhanced create() flow to set member collection via bidirectional setter. Modified quitFamilyRoom() to retrieve and decrement wish counts for both standard and transformed recipes before profile deletion.
New Withdrawal Service
AuthService.java
Created new service class with withdraw(Long memberId) method that retrieves associated FamilyMemberProfile, decrements wish counts for all linked recipe wishes, deletes the profile, and finally deletes the Member—ensuring cascading cleanup and referential integrity.
Controller Integration
AuthController.java
Updated withdraw endpoint to delegate member deletion to AuthService.withdraw() instead of direct repository deletion, enabling coordinated cleanup logic.

Sequence Diagram

sequenceDiagram
    participant Client
    participant AuthController
    participant AuthService
    participant MemberRepo as MemberRepository
    participant FamilyRepo as FamilyMemberProfileRepository
    participant WishListRepo as MemberWishListRepository
    participant TransWishRepo as MemberTransformedRecipeWishRepository

    Client->>AuthController: withdraw(memberId)
    AuthController->>AuthService: withdraw(memberId)
    
    AuthService->>MemberRepo: findById(memberId)
    MemberRepo-->>AuthService: Member
    
    AuthService->>FamilyRepo: findByMember(member)
    FamilyRepo-->>AuthService: FamilyMemberProfile (optional)
    
    alt Profile exists
        AuthService->>WishListRepo: findMemberWishListsByFamilyMemberProfile_Id(profileId)
        WishListRepo-->>AuthService: List<MemberWishList>
        
        Note over AuthService: Extract recipe IDs
        AuthService->>WishListRepo: decreaseWishCount(recipeIds)
        WishListRepo-->>AuthService: ✓
        
        AuthService->>TransWishRepo: findMemberTransformedRecipeWishesByFamilyMemberProfile_Id(profileId)
        TransWishRepo-->>AuthService: List<MemberTransformedRecipeWish>
        
        Note over AuthService: Extract recipe IDs
        AuthService->>TransWishRepo: decreaseWishCount(recipeIds)
        TransWishRepo-->>AuthService: ✓
        
        AuthService->>FamilyRepo: delete(profile)
        FamilyRepo-->>AuthService: ✓
    end
    
    AuthService->>MemberRepo: delete(member)
    MemberRepo-->>AuthService: ✓
    AuthService-->>AuthController: ✓
    AuthController-->>Client: 200 OK
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

♻️refactor

Poem

🐰 Hop, hop, huzzah! The members dance,
With profiles linked in sweet romance,
Their wishes flutter, neat and clean,
The cleanest withdrawal ever seen!
Cascade and sync, all hearts align—
A refactored family now divine!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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.

@chunny-k
chunny-k merged commit da9a98f into main Feb 12, 2026
2 of 5 checks passed
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.

1 participant