From 19e8b0294082fde6f21aa093733619893c5b25ec Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Wed, 23 Oct 2024 22:34:38 +0900 Subject: [PATCH 1/5] =?UTF-8?q?Fix:=20readExamHistoryList=20=EB=B3=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=8B=9C=ED=97=98=EB=A7=8C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/swm_standard/phote/controller/ExamController.kt | 3 ++- .../kotlin/com/swm_standard/phote/service/ExamService.kt | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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..227798a 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,11 @@ 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") + examResultRepository.findByExamIdAndMemberId(exam.id!!, memberId) ReadExamHistoryListResponse( examId = exam.id!!, From 92138dcc184e29073a1b4157a6dbd5db551991fc Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Thu, 24 Oct 2024 00:21:18 +0900 Subject: [PATCH 2/5] =?UTF-8?q?Fix:=20sharedExam=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/swm_standard/phote/service/ExamService.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 227798a..8246529 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -110,9 +110,11 @@ class ExamService( fun readExamHistoryList(workbookId: UUID, memberId: UUID): List { val exams = examRepository.findAllByWorkbookId(workbookId) - return exams.map { exam -> - val examResult = - examResultRepository.findByExamIdAndMemberId(exam.id!!, memberId) + + return exams.filter { exam -> + !sharedExamRepository.findById(exam.id!!).isPresent + }.map { exam -> + val examResult = examResultRepository.findByExamIdAndMemberId(exam.id!!, memberId) ReadExamHistoryListResponse( examId = exam.id!!, From a112c9dd56e481baa528b5e383da9f7a63c028c4 Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Thu, 24 Oct 2024 00:23:06 +0900 Subject: [PATCH 3/5] =?UTF-8?q?Fix:=20404=20=EC=97=90=EB=9F=AC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=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/service/ExamService.kt | 1 + 1 file changed, 1 insertion(+) 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 8246529..212b8a2 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/ExamService.kt @@ -115,6 +115,7 @@ class ExamService( !sharedExamRepository.findById(exam.id!!).isPresent }.map { exam -> val examResult = examResultRepository.findByExamIdAndMemberId(exam.id!!, memberId) + ?: throw NotFoundException(fieldName = "examResult") ReadExamHistoryListResponse( examId = exam.id!!, From e274ec9a527a978baed169ed0ebfec12ad60d51a Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Thu, 24 Oct 2024 11:43:20 +0900 Subject: [PATCH 4/5] =?UTF-8?q?Refactor:=20=EC=BD=94=EB=A3=A8=ED=8B=B4=20?= =?UTF-8?q?=EB=B9=84=EB=8F=99=EA=B8=B0=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../phote/service/QuestionService.kt | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) 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..23ee9a4 100644 --- a/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt +++ b/src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt @@ -17,9 +17,7 @@ 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.Dispatchers -import kotlinx.coroutines.async +import kotlinx.coroutines.* import org.springframework.beans.factory.annotation.Value import org.springframework.http.HttpHeaders import org.springframework.http.MediaType @@ -127,26 +125,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( From 0ef0d3e0ea588f5ea0410a1842cb749671db468e Mon Sep 17 00:00:00 2001 From: RinRinPARK Date: Thu, 24 Oct 2024 16:08:34 +0900 Subject: [PATCH 5/5] =?UTF-8?q?Style:=20import=EB=AC=B8=20=EC=99=80?= =?UTF-8?q?=EC=9D=BC=EB=93=9C=EC=B9=B4=EB=93=9C=20=EC=A0=9C=EA=B1=B0:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/swm_standard/phote/service/QuestionService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 23ee9a4..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,10 @@ 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.* +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.withContext +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async import org.springframework.beans.factory.annotation.Value import org.springframework.http.HttpHeaders import org.springframework.http.MediaType