Skip to content

Commit

Permalink
fix: 수강 이력 조회 시 studyId를 이용하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Nov 6, 2024
1 parent f9dc1c3 commit acbcfdf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class MentorStudyHistoryService {
public void completeStudy(Long studyId, StudyCompletionRequest request) {
Member currentMember = memberUtil.getCurrentMember();
Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));
List<StudyHistory> studyHistories = studyHistoryRepository.findAllById(request.studentIds());
List<StudyHistory> studyHistories =
studyHistoryRepository.findAllByStudyIdAndStudentIds(studyId, request.studentIds());

studyValidator.validateStudyMentor(currentMember, study);
studyHistoryValidator.validateAppliedToStudy(
Expand All @@ -48,7 +49,8 @@ public void completeStudy(Long studyId, StudyCompletionRequest request) {
public void withdrawStudyCompletion(Long studyId, StudyCompletionRequest request) {
Member currentMember = memberUtil.getCurrentMember();
Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));
List<StudyHistory> studyHistories = studyHistoryRepository.findAllById(request.studentIds());
List<StudyHistory> studyHistories =
studyHistoryRepository.findAllByStudyIdAndStudentIds(studyId, request.studentIds());

studyValidator.validateStudyMentor(currentMember, study);
studyHistoryValidator.validateAppliedToStudy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.gdschongik.gdsc.domain.study.dao;

import com.gdschongik.gdsc.domain.study.domain.StudyHistory;
import java.util.List;

public interface StudyHistoryCustomRepository {

long countByStudyIdAndStudentIds(Long studyId, List<Long> studentIds);

List<StudyHistory> findAllByStudyIdAndStudentIds(Long studyId, List<Long> studentIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.gdschongik.gdsc.domain.study.domain.QStudyHistory.*;

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;
Expand All @@ -21,6 +22,14 @@ public long countByStudyIdAndStudentIds(Long studyId, List<Long> studentIds) {
.fetchOne();
}

@Override
public List<StudyHistory> findAllByStudyIdAndStudentIds(Long studyId, List<Long> studentIds) {
return queryFactory
.selectFrom(studyHistory)
.where(eqStudyId(studyId), studyHistory.student.id.in(studentIds))
.fetch();
}

private BooleanExpression eqStudyId(Long studyId) {
return studyHistory.study.id.eq(studyId);
}
Expand Down

0 comments on commit acbcfdf

Please sign in to comment.