diff --git a/src/main/java/gdsc/binaryho/imhere/core/enrollment/infrastructure/EnrollmentInfoRepository.java b/src/main/java/gdsc/binaryho/imhere/core/enrollment/infrastructure/EnrollmentInfoRepository.java index 669950e..f882d3e 100644 --- a/src/main/java/gdsc/binaryho/imhere/core/enrollment/infrastructure/EnrollmentInfoRepository.java +++ b/src/main/java/gdsc/binaryho/imhere/core/enrollment/infrastructure/EnrollmentInfoRepository.java @@ -3,7 +3,6 @@ import gdsc.binaryho.imhere.core.enrollment.EnrollmentInfo; import gdsc.binaryho.imhere.core.enrollment.EnrollmentState; import gdsc.binaryho.imhere.core.lecture.Lecture; -import gdsc.binaryho.imhere.core.lecture.LectureState; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,7 +10,6 @@ public interface EnrollmentInfoRepository extends JpaRepository { List findAllByMemberIdAndEnrollmentState(Long memberId, EnrollmentState enrollmentState); - List findAllByMemberIdAndLecture_LectureStateAndEnrollmentState(Long memberId, LectureState lectureState, EnrollmentState enrollmentState); List findAllByLecture(Lecture lecture); List findAllByLectureAndEnrollmentState(Lecture lecture, EnrollmentState enrollmentState); Optional findByMemberIdAndLectureIdAndEnrollmentState(Long memberId, Long lectureId, EnrollmentState enrollmentState); diff --git a/src/main/java/gdsc/binaryho/imhere/core/lecture/application/LectureService.java b/src/main/java/gdsc/binaryho/imhere/core/lecture/application/LectureService.java index a4459f6..ec3ad0a 100644 --- a/src/main/java/gdsc/binaryho/imhere/core/lecture/application/LectureService.java +++ b/src/main/java/gdsc/binaryho/imhere/core/lecture/application/LectureService.java @@ -59,21 +59,10 @@ private List findStudentLectures(Member currentStudent) { @Transactional(readOnly = true) public LectureResponse getStudentOpenLectures() { Member currentStudent = authenticationHelper.getCurrentMember(); - List studentOpenLectures = findStudentOpenLectures(currentStudent); - + List studentOpenLectures = lectureRepository.findOpenAndApprovalLecturesByMemberId(currentStudent.getId()); return LectureResponse.createLectureResponseFromLectures(studentOpenLectures); } - private List findStudentOpenLectures(Member currentStudent) { - List enrollmentInfos = enrollmentInfoRepository - .findAllByMemberIdAndLecture_LectureStateAndEnrollmentState( - currentStudent.getId(), LectureState.OPEN, EnrollmentState.APPROVAL); - - return enrollmentInfos.stream() - .map(EnrollmentInfo::getLecture) - .collect(Collectors.toList()); - } - @Transactional(readOnly = true) public LectureResponse getOwnedLectures() { Member currentLecturer = authenticationHelper.getCurrentMember(); diff --git a/src/main/java/gdsc/binaryho/imhere/core/lecture/infrastructure/LectureRepository.java b/src/main/java/gdsc/binaryho/imhere/core/lecture/infrastructure/LectureRepository.java index aea1255..9dad480 100644 --- a/src/main/java/gdsc/binaryho/imhere/core/lecture/infrastructure/LectureRepository.java +++ b/src/main/java/gdsc/binaryho/imhere/core/lecture/infrastructure/LectureRepository.java @@ -2,13 +2,17 @@ import gdsc.binaryho.imhere.core.lecture.Lecture; import gdsc.binaryho.imhere.core.lecture.LectureState; +import io.lettuce.core.dynamic.annotation.Param; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface LectureRepository extends JpaRepository { Optional findById(Long id); List findAllByMemberId(Long id); List findAllByLectureStateNot(LectureState lectureState); + @Query("SELECT e.lecture FROM EnrollmentInfo e WHERE e.member.id = :memberId AND e.enrollmentState = 'APPROVAL' AND e.lecture.lectureState = 'OPEN'") + List findOpenAndApprovalLecturesByMemberId(@Param("memberId") Long memberId); } diff --git a/src/test/java/gdsc/binaryho/imhere/core/lecture/application/LectureServiceTest.java b/src/test/java/gdsc/binaryho/imhere/core/lecture/application/LectureServiceTest.java index ee08291..99e9d6c 100644 --- a/src/test/java/gdsc/binaryho/imhere/core/lecture/application/LectureServiceTest.java +++ b/src/test/java/gdsc/binaryho/imhere/core/lecture/application/LectureServiceTest.java @@ -116,10 +116,8 @@ void initServices() { EnrollmentInfo enrollmentInfo = EnrollmentInfo .createEnrollmentInfo(OPEN_LECTURE, MemberFixture.STUDENT, EnrollmentState.APPROVAL); - given(enrollmentInfoRepository - .findAllByMemberIdAndLecture_LectureStateAndEnrollmentState( - 1L, LectureState.OPEN, EnrollmentState.APPROVAL)) - .willReturn(List.of(enrollmentInfo)); + given(lectureRepository.findOpenAndApprovalLecturesByMemberId(1L)) + .willReturn(List.of(OPEN_LECTURE)); Long expectedOpenLectureId = enrollmentInfo.getLecture().getId();