Skip to content

Commit

Permalink
Merge pull request #264 from swm-standard/develop
Browse files Browse the repository at this point in the history
CD: release 배포
  • Loading branch information
RinRinPARK authored Oct 25, 2024
2 parents 20a4ca4 + 38d06c0 commit b34bca7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class ExamController(
@PathVariable(
required = true,
) workbookId: UUID,
@MemberId memberId: UUID,
): BaseResponse<List<ReadExamHistoryListResponse>> =
BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId))
BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId, memberId))

@Operation(summary = "readExamResults", description = "(강사가) 학생들의 시험 결과 목록을 조회")
@SecurityRequirement(name = "bearer Auth")
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/com/swm_standard/phote/service/ExamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ class ExamService(
)
}

fun readExamHistoryList(workbookId: UUID): List<ReadExamHistoryListResponse> {
fun readExamHistoryList(workbookId: UUID, memberId: UUID): List<ReadExamHistoryListResponse> {
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!!,
Expand Down
45 changes: 25 additions & 20 deletions src/main/kotlin/com/swm_standard/phote/service/QuestionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -127,26 +128,30 @@ class QuestionService(
imageUrl: String,
imageCoordinates: List<List<Int>>?,
): 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<String?>
lateinit var chatGPTResponseSplitDeferred: Deferred<List<String>>

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(
Expand Down

0 comments on commit b34bca7

Please sign in to comment.