diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java index ff3456d0d..792c71224 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/CommonStudyService.java @@ -59,22 +59,14 @@ public List getStudyAnnouncements(Long studyId) { /** * 이벤트 핸들러에서 사용되므로, `@Transactional` 을 사용하지 않습니다. */ - public void deleteAttendanceByStudyHistory(Long studyHistoryId) { - StudyHistory studyHistory = studyHistoryRepository - .findById(studyHistoryId) - .orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND)); - - attendanceRepository.deleteByStudyHistory(studyHistory); + public void deleteAttendance(Long studyId, Long memberId) { + attendanceRepository.deleteByStudyIdAndMemberId(studyId, memberId); } /** * 이벤트 핸들러에서 사용되므로, `@Transactional` 을 사용하지 않습니다. */ - public void deleteAssignmentHistoryByStudyHistory(Long studyHistoryId) { - StudyHistory studyHistory = studyHistoryRepository - .findById(studyHistoryId) - .orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND)); - - assignmentHistoryRepository.deleteByStudyHistory(studyHistory); + public void deleteAssignmentHistory(Long studyId, Long memberId) { + assignmentHistoryRepository.deleteByStudyIdAndMemberId(studyId, memberId); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudyEventHandler.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudyEventHandler.java index 521155f1e..45e29a8fa 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudyEventHandler.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudyEventHandler.java @@ -16,8 +16,8 @@ public class StudyEventHandler { @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) public void handleStudyApplyCanceledEvent(StudyApplyCanceledEvent event) { - log.info("[StudyEventHandler] 스터디 수강신청 취소 이벤트 수신: studyHistoryId={}", event.studyHistoryId()); - commonStudyService.deleteAttendanceByStudyHistory(event.studyHistoryId()); - commonStudyService.deleteAssignmentHistoryByStudyHistory(event.studyHistoryId()); + log.info("[StudyEventHandler] 스터디 수강신청 취소 이벤트 수신: studyId={}, memberId={}", event.studyId(), event.memberId()); + commonStudyService.deleteAttendance(event.studyId(), event.memberId()); + commonStudyService.deleteAssignmentHistory(event.studyId(), event.memberId()); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepository.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepository.java index c1eb52a81..cd5addbc8 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepository.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepository.java @@ -3,7 +3,6 @@ import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory; import com.gdschongik.gdsc.domain.study.domain.Study; -import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import java.util.List; public interface AssignmentHistoryCustomRepository { @@ -12,5 +11,5 @@ public interface AssignmentHistoryCustomRepository { List findAssignmentHistoriesByStudentAndStudyId(Member member, Long studyId); - void deleteByStudyHistory(StudyHistory studyHistory); + void deleteByStudyIdAndMemberId(Long studyId, Long memberId); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepositoryImpl.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepositoryImpl.java index 598379fe8..df884bfc6 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepositoryImpl.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AssignmentHistoryCustomRepositoryImpl.java @@ -7,7 +7,6 @@ import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory; import com.gdschongik.gdsc.domain.study.domain.Study; -import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; @@ -56,10 +55,14 @@ private BooleanExpression eqStudyId(Long studyId) { } @Override - public void deleteByStudyHistory(StudyHistory studyHistory) { + public void deleteByStudyIdAndMemberId(Long studyId, Long memberId) { queryFactory .delete(assignmentHistory) - .where(eqMember(studyHistory.getStudent()).and(eqStudy(studyHistory.getStudy()))) + .where(eqMemberId(memberId), eqStudyId(studyId)) .execute(); } + + private BooleanExpression eqMemberId(Long memberId) { + return memberId != null ? assignmentHistory.member.id.eq(memberId) : null; + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepository.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepository.java index 915756630..e04482f5d 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepository.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepository.java @@ -2,11 +2,10 @@ import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.Attendance; -import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import java.util.List; public interface AttendanceCustomRepository { List findByMemberAndStudyId(Member member, Long studyId); - void deleteByStudyHistory(StudyHistory studyHistory); + void deleteByStudyIdAndMemberId(Long studyId, Long memberId); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepositoryImpl.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepositoryImpl.java index f4bd3fb0f..af382f4d2 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepositoryImpl.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/AttendanceCustomRepositoryImpl.java @@ -6,7 +6,6 @@ import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.Attendance; -import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.List; @@ -36,13 +35,10 @@ private BooleanExpression eqStudyId(Long studyId) { } @Override - public void deleteByStudyHistory(StudyHistory studyHistory) { + public void deleteByStudyIdAndMemberId(Long studyId, Long memberId) { queryFactory .delete(attendance) - .where(attendance - .student - .eq(studyHistory.getStudent()) - .and(attendance.studyDetail.study.eq(studyHistory.getStudy()))) + .where(eqMemberId(memberId), eqStudyId(studyId)) .execute(); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyApplyCanceledEvent.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyApplyCanceledEvent.java index 94894812b..0b737cf1c 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyApplyCanceledEvent.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyApplyCanceledEvent.java @@ -1,3 +1,3 @@ package com.gdschongik.gdsc.domain.study.domain; -public record StudyApplyCanceledEvent(Long studyHistoryId) {} +public record StudyApplyCanceledEvent(Long studyId, Long memberId) {} diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java index 3129beb4f..854a5001d 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyHistory.java @@ -51,7 +51,7 @@ public static StudyHistory create(Member student, Study study) { @PreRemove private void preRemove() { - registerEvent(new StudyApplyCanceledEvent(this.id)); + registerEvent(new StudyApplyCanceledEvent(this.study.getId(), this.student.getId())); } /**