From 45b6c8db9683a6be33d360d7e1101210057d3a91 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 6 Aug 2025 22:19:52 +0900 Subject: [PATCH] =?UTF-8?q?git=20commit=20-m=20"fix(chat):=20=EC=BA=90?= =?UTF-8?q?=EB=A6=AD=ED=84=B0=20=EB=93=B1=EB=A1=9D/=EC=88=98=EC=A0=95=20AP?= =?UTF-8?q?I?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이름 중복 검사 로직 추가 --- .../character/AdminChatCharacterController.kt | 21 +++++++++++++++++-- .../character/service/ChatCharacterService.kt | 5 ++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/character/AdminChatCharacterController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/character/AdminChatCharacterController.kt index 070719e..806d665 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/character/AdminChatCharacterController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/character/AdminChatCharacterController.kt @@ -57,6 +57,12 @@ class AdminChatCharacterController( val objectMapper = ObjectMapper() val request = objectMapper.readValue(requestString, ChatCharacterRegisterRequest::class.java) + // 외부 API 호출 전 DB에 동일한 이름이 있는지 조회 + val existingCharacter = service.findByName(request.name) + if (existingCharacter != null) { + throw SodaException("동일한 이름은 등록이 불가능합니다: ${request.name}") + } + // 1. 외부 API 호출 val characterUUID = callExternalApi(request) @@ -188,6 +194,15 @@ class AdminChatCharacterController( if (hasChangedData) { val chatCharacter = service.findById(request.id) ?: throw SodaException("해당 ID의 캐릭터를 찾을 수 없습니다: ${request.id}") + + // 이름이 수정된 경우 DB에 동일한 이름이 있는지 확인 + if (request.name != null && request.name != chatCharacter.name) { + val existingCharacter = service.findByName(request.name) + if (existingCharacter != null) { + throw SodaException("동일한 이름은 등록이 불가능합니다: ${request.name}") + } + } + callExternalApiForUpdate(chatCharacter.characterUUID, request) } @@ -261,8 +276,11 @@ class AdminChatCharacterController( // 변경된 데이터만 포함하는 맵 생성 val updateData = mutableMapOf() + // isActive = false인 경우 처리 if (request.isActive != null && !request.isActive) { - updateData["name"] = "inactive_${request.name}" + val inactiveName = "inactive_${request.name}" + val randomSuffix = "_" + java.util.UUID.randomUUID().toString().replace("-", "") + updateData["name"] = inactiveName + randomSuffix } else { request.name?.let { updateData["name"] = it } request.systemPrompt?.let { updateData["systemPrompt"] = it } @@ -284,7 +302,6 @@ class AdminChatCharacterController( } val httpEntity = HttpEntity(updateData, headers) - val response = restTemplate.exchange( "$apiUrl/api/characters/$characterUUID", HttpMethod.PUT, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt index af72b69..ab4254a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt @@ -292,7 +292,10 @@ class ChatCharacterService( // isActive가 false이면 isActive = false, name = "inactive_$name"으로 변경하고 나머지는 반영하지 않는다. if (request.isActive != null && !request.isActive) { chatCharacter.isActive = false - chatCharacter.name = "inactive_${chatCharacter.name}" + + val inactiveName = "inactive_${request.name}" + val randomSuffix = "_" + java.util.UUID.randomUUID().toString().replace("-", "") + chatCharacter.name = inactiveName + randomSuffix return saveChatCharacter(chatCharacter) }