Skip to content

Commit

Permalink
REFACTOR: ExamSubmissionServic에서 메서드 호출 방식 변경
Browse files Browse the repository at this point in the history
- getStudentExamResult 메서드에서 문제별 답안 조회 구현부 수정
- getExamResults 메서드에서 findAllByExamId를 findByExamId로 변경
  • Loading branch information
hyerin315 committed Nov 20, 2024
1 parent 2acc103 commit 54fe978
Showing 1 changed file with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,42 +240,38 @@ public ExamResultDetailDto getStudentExamResult(Long courseId, Long examId, Stri
// 1. 시험 결과 조회
ExamResult examResult = examResultRepository.findByExamIdAndStudentEmail(examId, studentEmail)
.orElseThrow(() -> new BusinessBaseException(ErrorCode.EXAM_RESULT_NOT_FOUND));

// 2. 시험 정보 조회
Exam exam = examRepository.findById(examId)
.orElseThrow(() -> new BusinessBaseException(ErrorCode.EXAM_NOT_FOUND));

// 3. 문제별 답안 조회
List<ExamAnswer> answers = examAnswerRepository.findByExamIdAndStudentEmail(examId, studentEmail);

// 4. DTO 변환
List<QuestionResultDto> questionResults = answers.stream()
.map(answer -> QuestionResultDto.builder()
.questionId(answer.getQuestionId())
.questionTitle(answer.getQuestion().getTitle())
.studentAnswer(answer.getAnswer())
.score(answer.getScore())
.build())

// 3. 문제별 답안 조회 (ExamScore 사용)
List<QuestionResultDto> questionResults = examResult.getScores().stream()
.<QuestionResultDto>map(score -> QuestionResultDto.builder()
.questionId(score.getQuestion().getId())
.questionTitle(score.getQuestion().getQuestionText()) // title -> questionText로 변경
.studentAnswer(score.getStudentAnswer())
.score(score.getEarnedScore())
.build())
.collect(Collectors.toList());

return ExamResultDetailDto.builder()
.examId(examId)
.examTitle(exam.getTitle())
.startTime(examResult.getStartTime())
.endTime(examResult.getSubmitTime())
.status(examResult.getStatus())
.totalScore(examResult.getTotalScore())
.totalScore(examResult.getEarnedScore())
.questionResults(questionResults)
.build();
}

public List<ExamResultSummaryDto> getExamResults(Long courseId, Long examId) {
return examResultRepository.findAllByExamId(examId).stream()
return examResultRepository.findByExamId(examId).stream()
.map(result -> ExamResultSummaryDto.builder()
.studentName(result.getStudent().getName())
.studentEmail(result.getStudent().getEmail())
.status(result.getStatus())
.totalScore(result.getTotalScore())
.totalScore(result.getEarnedScore())
.submittedAt(result.getSubmitTime())
.build())
.collect(Collectors.toList());
Expand Down

0 comments on commit 54fe978

Please sign in to comment.