From f7262d7366e23d2d176ae2f2747fca6bc6ca780b Mon Sep 17 00:00:00 2001 From: Jaehyun Ahn <91878695+uwoobeat@users.noreply.github.com> Date: Wed, 4 Sep 2024 22:42:17 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=82=AD=EC=A0=9C=20=EC=9D=B4=EB=B2=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=97=B0=EA=B4=80=20=EA=B0=9D=EC=B2=B4=20ID?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EC=95=84=EC=84=9C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 참조 ID를 받아서 처리하도록 변경 --- .../study/application/CommonStudyService.java | 16 ++++------------ .../study/application/StudyEventHandler.java | 6 +++--- .../dao/AssignmentHistoryCustomRepository.java | 3 +-- .../AssignmentHistoryCustomRepositoryImpl.java | 9 ++++++--- .../study/dao/AttendanceCustomRepository.java | 3 +-- .../dao/AttendanceCustomRepositoryImpl.java | 8 ++------ .../study/domain/StudyApplyCanceledEvent.java | 2 +- .../gdsc/domain/study/domain/StudyHistory.java | 2 +- 8 files changed, 19 insertions(+), 30 deletions(-) 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())); } /**