Skip to content

Commit 5d2a16a

Browse files
committed
refactor: 계획에서 나가거나 추방될 경우 DB에서 바로 삭제
1 parent da3db4a commit 5d2a16a

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/plans/entity/Plan.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public void addParticipant(PlanParticipant participant) {
9292
participant.setPlan(this);
9393
}
9494

95+
public void removeParticipant(PlanParticipant participant) {
96+
this.participants.remove(participant);
97+
participant.setPlan(null);
98+
}
99+
95100
public void addSchedule(Schedule schedule) {
96101
this.schedules.add(schedule);
97102
schedule.setPlan(this);

src/main/java/com/back/web7_9_codecrete_be/domain/plans/service/PlanService.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,9 @@ public void kickParticipant(Long planId, Long participantId, User user) {
10911091
throw new BusinessException(PlanErrorCode.CANNOT_REMOVE_OWNER);
10921092
}
10931093

1094-
// 상태를 REMOVED로 변경
1095-
participant.updateInviteStatus(PlanParticipant.InviteStatus.REMOVED);
1094+
// 참가자 삭제 (Plan의 participants 리스트에서도 제거)
1095+
plan.removeParticipant(participant);
1096+
planParticipantRepository.delete(participant);
10961097
}
10971098

10981099
/**
@@ -1119,9 +1120,9 @@ public void quitPlan(Long planId, User user) {
11191120
.findByUser_IdAndPlan_PlanId(user.getId(), planId)
11201121
.orElseThrow(() -> new BusinessException(PlanErrorCode.PARTICIPANT_NOT_FOUND));
11211122

1122-
// 상태를 LEFT로 변경
1123-
participant.updateInviteStatus(PlanParticipant.InviteStatus.LEFT);
1124-
planParticipantRepository.save(participant);
1123+
// 참가자 삭제 (Plan의 participants 리스트에서도 제거)
1124+
plan.removeParticipant(participant);
1125+
planParticipantRepository.delete(participant);
11251126
// 명시적으로 flush하여 OptimisticLockException을 즉시 감지
11261127
planParticipantRepository.flush();
11271128
} catch (OptimisticLockException e) {

0 commit comments

Comments
 (0)