Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
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;

public interface EnrollmentInfoRepository extends JpaRepository<EnrollmentInfo, Long> {

List<EnrollmentInfo> findAllByMemberIdAndEnrollmentState(Long memberId, EnrollmentState enrollmentState);
List<EnrollmentInfo> findAllByMemberIdAndLecture_LectureStateAndEnrollmentState(Long memberId, LectureState lectureState, EnrollmentState enrollmentState);
List<EnrollmentInfo> findAllByLecture(Lecture lecture);
List<EnrollmentInfo> findAllByLectureAndEnrollmentState(Lecture lecture, EnrollmentState enrollmentState);
Optional<EnrollmentInfo> findByMemberIdAndLectureIdAndEnrollmentState(Long memberId, Long lectureId, EnrollmentState enrollmentState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,10 @@ private List<Lecture> findStudentLectures(Member currentStudent) {
@Transactional(readOnly = true)
public LectureResponse getStudentOpenLectures() {
Member currentStudent = authenticationHelper.getCurrentMember();
List<Lecture> studentOpenLectures = findStudentOpenLectures(currentStudent);

List<Lecture> studentOpenLectures = lectureRepository.findOpenAndApprovalLecturesByMemberId(currentStudent.getId());
return LectureResponse.createLectureResponseFromLectures(studentOpenLectures);
}

private List<Lecture> findStudentOpenLectures(Member currentStudent) {
List<EnrollmentInfo> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lecture, Long> {

Optional<Lecture> findById(Long id);
List<Lecture> findAllByMemberId(Long id);
List<Lecture> 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<Lecture> findOpenAndApprovalLecturesByMemberId(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down