Skip to content

Commit

Permalink
[fix] 회원탈퇴 시 혼자 만든 약속 삭제하도록 수정 (#149)
Browse files Browse the repository at this point in the history
* [fix] #148 modify to delete promises made alone when withdrawal

* [fix] #148 change to uppercase
  • Loading branch information
chaewonni authored Sep 12, 2024
1 parent a32823c commit fbad854
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ SELECT CASE WHEN EXISTS (

Member findByMeetingIdAndUserId(Long meetingId, Long userId);

@Query("""
SELECT m from Member m
JOIN FETCH m.meeting
WHERE m.user.id = :userId
""")
List<Member> findByUserId(Long userId);

@Query("""
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/kkumulkkum/server/service/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.kkumulkkum.server.service.member.MemberRemover;
import org.kkumulkkum.server.service.member.MemberRetreiver;
import org.kkumulkkum.server.service.participant.ParticipantRemover;
import org.kkumulkkum.server.service.participant.ParticipantRetriever;
import org.kkumulkkum.server.service.promise.PromiseRemover;
import org.kkumulkkum.server.service.promise.PromiseRetriever;
import org.kkumulkkum.server.service.user.UserRemover;
import org.kkumulkkum.server.service.user.UserRetriever;
import org.kkumulkkum.server.service.user.UserSaver;
Expand All @@ -45,6 +48,9 @@ public class AuthService {
private final TokenRemover tokenRemover;
private final UserInfoRetriever userInfoRetriever;
private final MemberRetreiver memberRetreiver;
private final PromiseRetriever promiseRetriever;
private final ParticipantRetriever participantRetriever;
private final PromiseRemover promiseRemover;
private final ParticipantRemover participantRemover;
private final MemberRemover memberRemover;
private final UserInfoRemover userInfoRemover;
Expand Down Expand Up @@ -148,6 +154,7 @@ private void deleteUser(final User user) {
// 각 Member에 대한 Participant 삭제
for(Member member : members) {
participantRemover.deleteByMemberId(member.getId());
removeEmptyPromises(member.getMeeting().getId());
}

// Member 데이터 삭제
Expand All @@ -158,4 +165,10 @@ private void deleteUser(final User user) {
// User 삭제
userRemover.delete(user);
}

private void removeEmptyPromises(final Long meetingId) {
promiseRetriever.findAllByMeetingId(meetingId).stream()
.filter(promise -> participantRetriever.findAllByPromiseId(promise.getId()).isEmpty())
.forEach(promise -> promiseRemover.deleteById(promise.getId()));
}
}

0 comments on commit fbad854

Please sign in to comment.