From dca8a02f9596b0d5ba3d9ea58efdb1bbe597b30d Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Mon, 14 Oct 2024 18:54:28 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20ReadExamResultDetail=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../phote/controller/ExamController.kt | 14 ++++++++ .../com/swm_standard/phote/dto/ExamDtos.kt | 20 +++++++++++ .../swm_standard/phote/service/ExamService.kt | 36 ++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) 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..9a5a775 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 memberId: UUID, + 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..2cdcfac 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,39 @@ 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, + ), + ) + } + } + } + + return ReadExamResultDetailResponse( + examId = examId, + memberId = memberId, + totalCorrect = examResult.totalCorrect, + time = examResult.time, + questions = responses, + createdAt = examResult.createdAt, + ) + } + @Transactional fun gradeExam( request: GradeExamRequest, From 88ed333fe2769679714827258a7910c5ae40b241 Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Mon, 14 Oct 2024 23:46:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20memberId=20->=20memberName=20?= =?UTF-8?q?=EB=A6=AC=ED=84=B4=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt | 2 +- src/main/kotlin/com/swm_standard/phote/service/ExamService.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) 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 9a5a775..8425dcb 100644 --- a/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt +++ b/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt @@ -60,7 +60,7 @@ data class ReadExamResultDetail( data class ReadExamResultDetailResponse( val examId: UUID, - val memberId: UUID, + val memberName: String, val totalCorrect: Int, val time: Int, val createdAt: LocalDateTime, 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 2cdcfac..2f4a132 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -149,9 +149,11 @@ class ExamService( } } + val member = memberRepository.findById(memberId).orElseThrow { NotFoundException(fieldName = "memberId") } + return ReadExamResultDetailResponse( examId = examId, - memberId = memberId, + memberName = member.name, totalCorrect = examResult.totalCorrect, time = examResult.time, questions = responses,