diff --git a/src/main/kotlin/com/teamapi/palette/entity/chat/Chat.kt b/src/main/kotlin/com/teamapi/palette/entity/chat/Chat.kt index cd1a620..b639288 100644 --- a/src/main/kotlin/com/teamapi/palette/entity/chat/Chat.kt +++ b/src/main/kotlin/com/teamapi/palette/entity/chat/Chat.kt @@ -26,7 +26,7 @@ data class Chat( val roomId: Long, val userId: Long, val isAi: Boolean, - + val regenScope: Boolean = false, @Contextual val promptId: ObjectId? = null ) { diff --git a/src/main/kotlin/com/teamapi/palette/response/ErrorCode.kt b/src/main/kotlin/com/teamapi/palette/response/ErrorCode.kt index 2400b2b..178edfe 100644 --- a/src/main/kotlin/com/teamapi/palette/response/ErrorCode.kt +++ b/src/main/kotlin/com/teamapi/palette/response/ErrorCode.kt @@ -27,6 +27,7 @@ enum class ErrorCode( CHAT_FILTERED(HttpStatus.BAD_REQUEST, "부적절한 내용 감지. 내용을 수정 해 주세요."), MESSAGE_TYPE_NOT_MATCH(HttpStatus.BAD_REQUEST, "적절하지 않은 메시지 유형: '%s'. 메시지 유형 '%s'이(가) 필요합니다."), + QNA_INVALID_NOT_FULFILLED(HttpStatus.BAD_REQUEST, "모든 질문에 대해 대답하지 않았거나, 요청을 받을 수 없는 상태입니다."), QNA_INVALID_FULFILLED(HttpStatus.BAD_REQUEST, "이미 모든 질문에 대해 대답하였습니다."), QNA_INVALID_CHOICES(HttpStatus.BAD_REQUEST, "적절하지 않은 선택: '%s'. %s 선택지 중 하나가 필요합니다."), QNA_INVALID_GRID_CHOICES(HttpStatus.BAD_REQUEST, "적절하지 않은 그리드: (%s). 0~%d 선택지 중 하나가 필요합니다."), diff --git a/src/main/kotlin/com/teamapi/palette/service/RoomService.kt b/src/main/kotlin/com/teamapi/palette/service/RoomService.kt index bd559aa..2684044 100644 --- a/src/main/kotlin/com/teamapi/palette/service/RoomService.kt +++ b/src/main/kotlin/com/teamapi/palette/service/RoomService.kt @@ -104,9 +104,15 @@ class RoomService( val room = roomRepository.findById(roomId) ?: throw CustomException(ErrorCode.ROOM_NOT_FOUND) room.validateUser(sessionHolder) + val regenScope = chatRepository.getLatestChatByRoomId(roomId)?.regenScope == true + val me = sessionHolder.me() val qna = qnaRepository.getQnAByRoomId(roomId)!! + if (qna.qna.any { it.answer == null } || !regenScope) { + throw CustomException(ErrorCode.QNA_INVALID_NOT_FULFILLED) + } + chatEmitAdapter.emitChat( Chat( resource = ChatState.CHAT, diff --git a/src/main/kotlin/com/teamapi/palette/service/infra/GenerativeImageService.kt b/src/main/kotlin/com/teamapi/palette/service/infra/GenerativeImageService.kt index 8a9030f..6be13f0 100644 --- a/src/main/kotlin/com/teamapi/palette/service/infra/GenerativeImageService.kt +++ b/src/main/kotlin/com/teamapi/palette/service/infra/GenerativeImageService.kt @@ -93,33 +93,35 @@ class GenerativeImageService( e.printStackTrace() guaranteed = null } - if (guaranteed == null) { - chatEmitAdapter.emitChat( - Chat( - resource = ChatState.CHAT, - roomId = room.id!!, - userId = me, - isAi = true, - message = "이미지를 생성하는 도중 오류가 발생하였어요. ;.;" + if (guaranteed != null) { + try { + val uploaded = blobSaveAdapter.save(Base64.decode(guaranteed!!)) + + chatEmitAdapter.emitChat( + Chat( + resource = ChatState.IMAGE, + roomId = room.id!!, + userId = me, + isAi = true, + message = uploaded.blobUrl, + regenScope = true + ) ) - ) - return + return + } catch (e: Exception) { + e.printStackTrace() + } } - try { - val uploaded = blobSaveAdapter.save(Base64.decode(guaranteed!!)) - - chatEmitAdapter.emitChat( - Chat( - resource = ChatState.IMAGE, - roomId = room.id!!, - userId = me, - isAi = true, - message = uploaded.blobUrl - ) + chatEmitAdapter.emitChat( + Chat( + resource = ChatState.CHAT, + roomId = room.id!!, + userId = me, + isAi = true, + message = "이미지를 생성하는 도중 오류가 발생하였어요. ;.;", + regenScope = true ) - } catch (e: Exception) { - e.printStackTrace() - } + ) } }