Skip to content

Commit 3159f0c

Browse files
authored
Merge pull request #283 from prgrms-web-devcourse-final-project/refactor/#282
[Plan] 계획 나가기 & 강퇴됐을 경우 DB에서 바로 삭제
2 parents 067e190 + d9e3917 commit 3159f0c

2 files changed

Lines changed: 13 additions & 7 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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ private Plan findPlanWithOwnerCheck(Long planId, User user) {
500500
}
501501

502502
/**
503-
* Plan을 조회하고 수정/삭제 권한을 체크
504-
* OWNER 또는 EDITOR만 수정/삭제 가능
503+
* Plan을 조회하고 수정 권한을 체크
504+
* OWNER 또는 EDITOR만 수정 가능 (계획 수정, 일정 추가/수정/삭제, 참가자 관리 등)
505505
*
506506
* @param planId 계획 ID
507507
* @param user 현재 로그인한 사용자
@@ -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)