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 4df5a89..1cd9db7 100644 --- a/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt +++ b/src/main/kotlin/com/swm_standard/phote/controller/ExamController.kt @@ -52,8 +52,9 @@ class ExamController( @PathVariable( required = true, ) workbookId: UUID, + @MemberId memberId: UUID, ): BaseResponse> = - BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId)) + BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId, memberId)) @Operation(summary = "readExamResults", description = "(강사가) 학생들의 시험 결과 목록을 조회") @SecurityRequirement(name = "bearer Auth") 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 821b579..212b8a2 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -108,12 +108,14 @@ class ExamService( ) } - fun readExamHistoryList(workbookId: UUID): List { + fun readExamHistoryList(workbookId: UUID, memberId: UUID): List { val exams = examRepository.findAllByWorkbookId(workbookId) - return exams.map { exam -> - // FIXME: exam 마다 examResult 를 또 조회해야함 쿼리 개선 필요 - val examResult = - examResultRepository.findByExamId(exam.id!!) ?: throw NotFoundException(fieldName = "examResult") + + return exams.filter { exam -> + !sharedExamRepository.findById(exam.id!!).isPresent + }.map { exam -> + val examResult = examResultRepository.findByExamIdAndMemberId(exam.id!!, memberId) + ?: throw NotFoundException(fieldName = "examResult") ReadExamHistoryListResponse( examId = exam.id!!, diff --git a/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt b/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt index 9faf386..5871197 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt @@ -17,7 +17,8 @@ import com.swm_standard.phote.entity.Tag import com.swm_standard.phote.repository.MemberRepository import com.swm_standard.phote.repository.TagRepository import com.swm_standard.phote.repository.questionrepository.QuestionRepository -import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.withContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import org.springframework.beans.factory.annotation.Value @@ -127,26 +128,30 @@ class QuestionService( imageUrl: String, imageCoordinates: List>?, ): TransformQuestionResponse { - val transformedImageUrl = - CoroutineScope(Dispatchers.IO) - .async { - // 문제 그림 추출 - imageCoordinates?.let { transformImage(imageUrl, it) } - }.await() - - val chatGPTResponseSplit = - CoroutineScope(Dispatchers.IO) - .async { - // openAI로 메시지 전송 - val request = ChatGPTRequest(model, imageUrl) - val chatGPTResponse = template.postForObject(url, request, ChatGPTResponse::class.java) - - // openAI로부터 메시지 수신 - splitChatGPTResponse(chatGPTResponse) - }.await() - + lateinit var transformedImageUrlDeferred: Deferred + lateinit var chatGPTResponseSplitDeferred: Deferred> + + withContext(Dispatchers.IO) { + transformedImageUrlDeferred = async { + // 문제 그림 추출 + imageCoordinates?.let { transformImage(imageUrl, it) } + } + + chatGPTResponseSplitDeferred = async { + // openAI로 메시지 전송 + val request = ChatGPTRequest(model, imageUrl) + val chatGPTResponse = template.postForObject(url, request, ChatGPTResponse::class.java) + + // openAI로부터 메시지 수신 + splitChatGPTResponse(chatGPTResponse) + } + } // 문제 문항과 객관식을 분리해서 dto에 저장 - return TransformQuestionResponse(chatGPTResponseSplit[0], chatGPTResponseSplit.drop(1), transformedImageUrl) + return TransformQuestionResponse( + chatGPTResponseSplitDeferred.await()[0], + chatGPTResponseSplitDeferred.await().drop(1), + transformedImageUrlDeferred.await() + ) } suspend fun transformImage(