From 641a186c110b8b7e1ac6c8cf7e10cca8ccf9bb2b Mon Sep 17 00:00:00 2001 From: binary_ho Date: Mon, 14 Aug 2023 23:27:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor=20:=20=ED=95=99=EC=83=9D=EC=9D=B4?= =?UTF-8?q?=20=EC=9E=90=EC=8B=A0=EC=9D=98=20=EC=88=98=EA=B0=95=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=EC=9D=B4=20=EC=8A=B9=EC=9D=B8=EB=90=98=EC=97=88?= =?UTF-8?q?=EA=B3=A0,=20=EC=97=B4=EB=A0=A4=EC=9E=88=EB=8A=94=20=EA=B0=95?= =?UTF-8?q?=EC=9D=98=EB=A5=BC=20=EB=B0=94=EB=A1=9C=20=EA=B0=80=EC=A0=B8?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=98=EA=B3=A0=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=EC=9D=98=20EnrollmentInfoRepository=EC=9D=98=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C=20=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enrollment/infrastructure/EnrollmentInfoRepository.java | 2 -- .../imhere/core/lecture/infrastructure/LectureRepository.java | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) 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/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); } From 9c43ed5963b05b9f3c52d9935eb0c1b16e2e6bc0 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Mon, 14 Aug 2023 23:29:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20:=20LectureService=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=95=99=EC=83=9D=EC=9D=98=20=EC=B6=9C=EC=84=9D=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=9C=20=EA=B0=95=EC=9D=98=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=83=88=EB=A1=9C=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=ED=95=9C=20LectureRepository=EC=9D=98=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=8C=80=EC=B2=B4=ED=95=98=EA=B3=A0=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/lecture/application/LectureService.java | 13 +------------ .../lecture/application/LectureServiceTest.java | 6 ++---- 2 files changed, 3 insertions(+), 16 deletions(-) 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/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();