diff --git a/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt b/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt index ac25345..9c7a2d0 100644 --- a/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt +++ b/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt @@ -11,6 +11,7 @@ import com.swm_standard.phote.dto.RegradeExamResponse import com.swm_standard.phote.dto.ReadExamHistoryDetailResponse import com.swm_standard.phote.dto.ReadExamHistoryListResponse import com.swm_standard.phote.dto.ReadExamResultsResponse +import com.swm_standard.phote.dto.ReadExamResultDetailResponse import com.swm_standard.phote.service.ExamService import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter @@ -62,6 +63,19 @@ class ExamController( ): BaseResponse = BaseResponse(msg = "학생 시험 결과 조회 성공", data = examService.readExamResults(examId)) + @Operation(summary = "readExamResultDetail", description = "(강사가) 학생의 시험 결과 상세조회") + @SecurityRequirement(name = "bearer Auth") + @GetMapping("/exam/result/{examId}/{memberId}") + fun readExamResultDetail( + @PathVariable( + required = true, + ) examId: UUID, + @PathVariable( + required = true, + ) memberId: UUID, + ): BaseResponse = + BaseResponse(msg = "학생 시험 결과 상세조회 성공", data = examService.readExamResultDetail(examId, memberId)) + @Operation(summary = "gradeExam", description = "문제풀이 제출 및 채점") @SecurityRequirement(name = "bearer Auth") @PostMapping("/exam") diff --git a/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt b/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt index c1cc5b8..8425dcb 100644 --- a/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt +++ b/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt @@ -47,6 +47,26 @@ data class ReadExamResultsResponse( val students: List, ) +data class ReadExamResultDetail( + val statement: String, + val options: List?, + val image: String?, + val category: Category, + val answer: String, + val submittedAnswer: String?, + val isCorrect: Boolean, + val sequence: Int, +) + +data class ReadExamResultDetailResponse( + val examId: UUID, + val memberName: String, + val totalCorrect: Int, + val time: Int, + val createdAt: LocalDateTime, + val questions: List, +) + data class GradeExamRequest( val time: Int, val workbookId: UUID?, diff --git a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt index 6c95660..2f4a132 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -14,6 +14,8 @@ import com.swm_standard.phote.dto.ReadExamHistoryDetail import com.swm_standard.phote.dto.ReadExamHistoryDetailResponse import com.swm_standard.phote.dto.ReadExamHistoryListResponse import com.swm_standard.phote.dto.ReadExamResultsResponse +import com.swm_standard.phote.dto.ReadExamResultDetail +import com.swm_standard.phote.dto.ReadExamResultDetailResponse import com.swm_standard.phote.dto.ReadExamStudentResult import com.swm_standard.phote.dto.SubmittedAnswerRequest import com.swm_standard.phote.entity.Answer @@ -81,7 +83,6 @@ class ExamService( } } - // FIXME: 원래 createdAt 은 시험 생성일시임 return ReadExamHistoryDetailResponse( examId = id, totalCorrect = examResult.totalCorrect, @@ -125,6 +126,41 @@ class ExamService( return ReadExamResultsResponse(examId, exam.workbook.quantity, responses) } + fun readExamResultDetail(examId: UUID, memberId: UUID): ReadExamResultDetailResponse { + val examResult = examResultRepository.findByExamIdAndMemberId(examId, memberId) + val responses = + buildList { + examResult.answers.forEach { answer -> + val question = answer.question + if (question != null) { + add( + ReadExamResultDetail( + statement = question.statement, + options = question.options?.let { question.deserializeOptions() }, + image = question.image, + category = question.category, + answer = question.answer, + submittedAnswer = answer.submittedAnswer, + isCorrect = answer.isCorrect, + sequence = answer.sequence, + ), + ) + } + } + } + + val member = memberRepository.findById(memberId).orElseThrow { NotFoundException(fieldName = "memberId") } + + return ReadExamResultDetailResponse( + examId = examId, + memberName = member.name, + totalCorrect = examResult.totalCorrect, + time = examResult.time, + questions = responses, + createdAt = examResult.createdAt, + ) + } + @Transactional fun gradeExam( request: GradeExamRequest,