From 07890f151e23cc0c4ea42f44631d85a30868dc03 Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Sun, 6 Oct 2024 17:06:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20readExamResults=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 | 11 ++++++++++ .../com/swm_standard/phote/dto/ExamDtos.kt | 12 +++++++++++ .../phote/repository/ExamResultRepository.kt | 1 + .../swm_standard/phote/service/ExamService.kt | 20 +++++++++++++++++++ 4 files changed, 44 insertions(+) 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 26bc838..fac5fcf 100644 --- a/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt +++ b/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt @@ -8,6 +8,7 @@ import com.swm_standard.phote.dto.GradeExamRequest import com.swm_standard.phote.dto.GradeExamResponse 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.service.ExamService import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.Parameter @@ -48,6 +49,16 @@ class ExamController( ): BaseResponse> = BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId)) + @Operation(summary = "readExamResults", description = "(강사가) 학생들의 시험 결과 목록을 조회") + @SecurityRequirement(name = "bearer Auth") + @GetMapping("/exams/result/{examId}") + fun readExamResults( + @PathVariable( + required = true, + ) examId: UUID, + ): BaseResponse = + BaseResponse(msg = "학생 시험 결과 조회 성공", data = examService.readExamResults(examId)) + @Operation(summary = "gradeExam", description = "문제풀이 제출 및 채점") @SecurityRequirement(name = "bearer Auth") @PostMapping("/exam/{workbookId}") 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 bc8a3e9..3eee484 100644 --- a/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt +++ b/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt @@ -34,6 +34,18 @@ data class ReadExamHistoryListResponse( val sequence: Int, ) +data class ReadExamStudentResult( + val userId: UUID, + val name: String, + val score: Int, +) + +data class ReadExamResultsResponse( + val examId: UUID, + val totalQuestionCount: Int, + val students: List, +) + data class GradeExamRequest( val time: Int, val answers: List, diff --git a/src/main/kotlin/com/swm_standard/phote/repository/ExamResultRepository.kt b/src/main/kotlin/com/swm_standard/phote/repository/ExamResultRepository.kt index d2a3c45..70f8d51 100644 --- a/src/main/kotlin/com/swm_standard/phote/repository/ExamResultRepository.kt +++ b/src/main/kotlin/com/swm_standard/phote/repository/ExamResultRepository.kt @@ -6,4 +6,5 @@ import java.util.UUID interface ExamResultRepository : JpaRepository { fun findByExamId(examId: UUID): ExamResult? + fun findAllByExamId(examId: UUID): List } 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 bed7e8f..bf115d1 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -10,6 +10,8 @@ import com.swm_standard.phote.dto.GradeExamResponse 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.ReadExamStudentResult +import com.swm_standard.phote.dto.ReadExamResultsResponse import com.swm_standard.phote.dto.SubmittedAnswerRequest import com.swm_standard.phote.entity.Answer import com.swm_standard.phote.entity.Category @@ -54,6 +56,7 @@ class ExamService( @Value("\${openai.api.url}") lateinit var url: String + @Transactional(readOnly = true) fun readExamHistoryDetail(id: UUID): ReadExamHistoryDetailResponse { val examResult = examResultRepository.findByExamId(id) ?: throw NotFoundException(fieldName = "examResult") val responses = @@ -87,6 +90,7 @@ class ExamService( ) } + @Transactional(readOnly = true) fun readExamHistoryList(workbookId: UUID): List { val exams = examRepository.findAllByWorkbookId(workbookId) return exams.map { exam -> @@ -104,6 +108,22 @@ class ExamService( } } + @Transactional(readOnly = true) + fun readExamResults(examId: UUID): ReadExamResultsResponse { + val exam = examRepository.findById(examId).orElseThrow { NotFoundException(fieldName = "examId") } + val examResults = examResultRepository.findAllByExamId(examId) + + val responses = examResults.map { examResult -> + ReadExamStudentResult( + examResult.member.id, + examResult.member.name, + examResult.totalCorrect + ) + } + + return ReadExamResultsResponse(examId, exam.workbook.quantity, responses) + } + @Transactional fun gradeExam( workbookId: UUID, From 81cc767d1b3a5773fe715d6666b5042114bda7be Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Sun, 6 Oct 2024 23:18:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20transactional=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=EC=97=90=20=ED=92=80=EC=9D=B4=20=EC=86=8C?= =?UTF-8?q?=EC=9A=94=20=EC=8B=9C=EA=B0=84=20=EC=B6=94=EA=B0=80?= 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 | 1 + .../kotlin/com/swm_standard/phote/service/ExamService.kt | 6 ++---- 2 files changed, 3 insertions(+), 4 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 3eee484..6e00f98 100644 --- a/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt +++ b/src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt @@ -38,6 +38,7 @@ data class ReadExamStudentResult( val userId: UUID, val name: String, val score: Int, + val time: Int, ) data class ReadExamResultsResponse( 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 bf115d1..c1d5000 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -56,7 +56,6 @@ class ExamService( @Value("\${openai.api.url}") lateinit var url: String - @Transactional(readOnly = true) fun readExamHistoryDetail(id: UUID): ReadExamHistoryDetailResponse { val examResult = examResultRepository.findByExamId(id) ?: throw NotFoundException(fieldName = "examResult") val responses = @@ -90,7 +89,6 @@ class ExamService( ) } - @Transactional(readOnly = true) fun readExamHistoryList(workbookId: UUID): List { val exams = examRepository.findAllByWorkbookId(workbookId) return exams.map { exam -> @@ -108,7 +106,6 @@ class ExamService( } } - @Transactional(readOnly = true) fun readExamResults(examId: UUID): ReadExamResultsResponse { val exam = examRepository.findById(examId).orElseThrow { NotFoundException(fieldName = "examId") } val examResults = examResultRepository.findAllByExamId(examId) @@ -117,7 +114,8 @@ class ExamService( ReadExamStudentResult( examResult.member.id, examResult.member.name, - examResult.totalCorrect + examResult.totalCorrect, + examResult.time, ) }