feat(chat-character): 관계 name 필드 추가에 따른 등록/수정/조회 로직 및 DTO 반영
- 관계 스키마를 name, relationShip 구조로 일원화 - Admin/사용자 컨트롤러 조회 응답에서 관계를 객체로 반환하도록 수정 - 등록/수정 요청 DTO에 ChatCharacterRelationshipRequest(name, relationShip) 추가 - 서비스 계층 create/update/add 메소드 시그니처 및 매핑 로직 업데이트 - description 한 줄 소개 사용 전제 하의 관련 사용부 점검(엔티티 컬럼 구성은 기존 유지)
This commit is contained in:
parent
c525ec0330
commit
2dc5a29220
|
@ -126,7 +126,7 @@ class AdminChatCharacterController(
|
||||||
memories = request.memories.map { Triple(it.title, it.content, it.emotion) },
|
memories = request.memories.map { Triple(it.title, it.content, it.emotion) },
|
||||||
personalities = request.personalities.map { Pair(it.trait, it.description) },
|
personalities = request.personalities.map { Pair(it.trait, it.description) },
|
||||||
backgrounds = request.backgrounds.map { Pair(it.topic, it.description) },
|
backgrounds = request.backgrounds.map { Pair(it.topic, it.description) },
|
||||||
relationships = request.relationships
|
relationships = request.relationships.map { it.name to it.relationShip }
|
||||||
)
|
)
|
||||||
|
|
||||||
// 3. 이미지 저장 및 ChatCharacter에 이미지 path 설정
|
// 3. 이미지 저장 및 ChatCharacter에 이미지 path 설정
|
||||||
|
|
|
@ -20,7 +20,7 @@ data class ChatCharacterDetailResponse(
|
||||||
val hobbies: List<String>,
|
val hobbies: List<String>,
|
||||||
val values: List<String>,
|
val values: List<String>,
|
||||||
val goals: List<String>,
|
val goals: List<String>,
|
||||||
val relationships: List<String>,
|
val relationships: List<RelationshipResponse>,
|
||||||
val personalities: List<PersonalityResponse>,
|
val personalities: List<PersonalityResponse>,
|
||||||
val backgrounds: List<BackgroundResponse>,
|
val backgrounds: List<BackgroundResponse>,
|
||||||
val memories: List<MemoryResponse>
|
val memories: List<MemoryResponse>
|
||||||
|
@ -51,7 +51,7 @@ data class ChatCharacterDetailResponse(
|
||||||
hobbies = chatCharacter.hobbyMappings.map { it.hobby.hobby },
|
hobbies = chatCharacter.hobbyMappings.map { it.hobby.hobby },
|
||||||
values = chatCharacter.valueMappings.map { it.value.value },
|
values = chatCharacter.valueMappings.map { it.value.value },
|
||||||
goals = chatCharacter.goalMappings.map { it.goal.goal },
|
goals = chatCharacter.goalMappings.map { it.goal.goal },
|
||||||
relationships = chatCharacter.relationships.map { it.relationShip },
|
relationships = chatCharacter.relationships.map { RelationshipResponse(it.name, it.relationShip) },
|
||||||
personalities = chatCharacter.personalities.map {
|
personalities = chatCharacter.personalities.map {
|
||||||
PersonalityResponse(it.trait, it.description)
|
PersonalityResponse(it.trait, it.description)
|
||||||
},
|
},
|
||||||
|
@ -81,3 +81,8 @@ data class MemoryResponse(
|
||||||
val content: String,
|
val content: String,
|
||||||
val emotion: String
|
val emotion: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class RelationshipResponse(
|
||||||
|
val name: String,
|
||||||
|
val relationShip: String
|
||||||
|
)
|
||||||
|
|
|
@ -18,6 +18,11 @@ data class ChatCharacterMemoryRequest(
|
||||||
@JsonProperty("emotion") val emotion: String
|
@JsonProperty("emotion") val emotion: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class ChatCharacterRelationshipRequest(
|
||||||
|
@JsonProperty("name") val name: String,
|
||||||
|
@JsonProperty("relationShip") val relationShip: String
|
||||||
|
)
|
||||||
|
|
||||||
data class ChatCharacterRegisterRequest(
|
data class ChatCharacterRegisterRequest(
|
||||||
@JsonProperty("name") val name: String,
|
@JsonProperty("name") val name: String,
|
||||||
@JsonProperty("systemPrompt") val systemPrompt: String,
|
@JsonProperty("systemPrompt") val systemPrompt: String,
|
||||||
|
@ -32,7 +37,7 @@ data class ChatCharacterRegisterRequest(
|
||||||
@JsonProperty("hobbies") val hobbies: List<String> = emptyList(),
|
@JsonProperty("hobbies") val hobbies: List<String> = emptyList(),
|
||||||
@JsonProperty("values") val values: List<String> = emptyList(),
|
@JsonProperty("values") val values: List<String> = emptyList(),
|
||||||
@JsonProperty("goals") val goals: List<String> = emptyList(),
|
@JsonProperty("goals") val goals: List<String> = emptyList(),
|
||||||
@JsonProperty("relationships") val relationships: List<String> = emptyList(),
|
@JsonProperty("relationships") val relationships: List<ChatCharacterRelationshipRequest> = emptyList(),
|
||||||
@JsonProperty("personalities") val personalities: List<ChatCharacterPersonalityRequest> = emptyList(),
|
@JsonProperty("personalities") val personalities: List<ChatCharacterPersonalityRequest> = emptyList(),
|
||||||
@JsonProperty("backgrounds") val backgrounds: List<ChatCharacterBackgroundRequest> = emptyList(),
|
@JsonProperty("backgrounds") val backgrounds: List<ChatCharacterBackgroundRequest> = emptyList(),
|
||||||
@JsonProperty("memories") val memories: List<ChatCharacterMemoryRequest> = emptyList()
|
@JsonProperty("memories") val memories: List<ChatCharacterMemoryRequest> = emptyList()
|
||||||
|
@ -64,7 +69,7 @@ data class ChatCharacterUpdateRequest(
|
||||||
@JsonProperty("hobbies") val hobbies: List<String>? = null,
|
@JsonProperty("hobbies") val hobbies: List<String>? = null,
|
||||||
@JsonProperty("values") val values: List<String>? = null,
|
@JsonProperty("values") val values: List<String>? = null,
|
||||||
@JsonProperty("goals") val goals: List<String>? = null,
|
@JsonProperty("goals") val goals: List<String>? = null,
|
||||||
@JsonProperty("relationships") val relationships: List<String>? = null,
|
@JsonProperty("relationships") val relationships: List<ChatCharacterRelationshipRequest>? = null,
|
||||||
@JsonProperty("personalities") val personalities: List<ChatCharacterPersonalityRequest>? = null,
|
@JsonProperty("personalities") val personalities: List<ChatCharacterPersonalityRequest>? = null,
|
||||||
@JsonProperty("backgrounds") val backgrounds: List<ChatCharacterBackgroundRequest>? = null,
|
@JsonProperty("backgrounds") val backgrounds: List<ChatCharacterBackgroundRequest>? = null,
|
||||||
@JsonProperty("memories") val memories: List<ChatCharacterMemoryRequest>? = null
|
@JsonProperty("memories") val memories: List<ChatCharacterMemoryRequest>? = null
|
||||||
|
|
|
@ -14,8 +14,7 @@ class ChatCharacter(
|
||||||
// 캐릭터 이름 (API 키 내에서 유일해야 함)
|
// 캐릭터 이름 (API 키 내에서 유일해야 함)
|
||||||
var name: String,
|
var name: String,
|
||||||
|
|
||||||
// 캐릭터 설명
|
// 캐릭터 한 줄 소개
|
||||||
@Column(columnDefinition = "TEXT", nullable = false)
|
|
||||||
var description: String,
|
var description: String,
|
||||||
|
|
||||||
// AI 시스템 프롬프트
|
// AI 시스템 프롬프트
|
||||||
|
@ -113,8 +112,8 @@ class ChatCharacter(
|
||||||
}
|
}
|
||||||
|
|
||||||
// 관계 추가 헬퍼 메소드
|
// 관계 추가 헬퍼 메소드
|
||||||
fun addRelationship(relationShip: String) {
|
fun addRelationship(name: String, relationShip: String) {
|
||||||
val relationship = ChatCharacterRelationship(relationShip, this)
|
val relationship = ChatCharacterRelationship(name, relationShip, this)
|
||||||
relationships.add(relationship)
|
relationships.add(relationship)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import javax.persistence.ManyToOne
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
class ChatCharacterRelationship(
|
class ChatCharacterRelationship(
|
||||||
|
var name: String,
|
||||||
val relationShip: String,
|
val relationShip: String,
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import kr.co.vividnext.sodalive.chat.character.dto.CharacterDetailResponse
|
||||||
import kr.co.vividnext.sodalive.chat.character.dto.CharacterMainResponse
|
import kr.co.vividnext.sodalive.chat.character.dto.CharacterMainResponse
|
||||||
import kr.co.vividnext.sodalive.chat.character.dto.CharacterMemoryResponse
|
import kr.co.vividnext.sodalive.chat.character.dto.CharacterMemoryResponse
|
||||||
import kr.co.vividnext.sodalive.chat.character.dto.CharacterPersonalityResponse
|
import kr.co.vividnext.sodalive.chat.character.dto.CharacterPersonalityResponse
|
||||||
|
import kr.co.vividnext.sodalive.chat.character.dto.CharacterRelationshipResponse
|
||||||
import kr.co.vividnext.sodalive.chat.character.dto.CurationSection
|
import kr.co.vividnext.sodalive.chat.character.dto.CurationSection
|
||||||
import kr.co.vividnext.sodalive.chat.character.dto.RecentCharacter
|
import kr.co.vividnext.sodalive.chat.character.dto.RecentCharacter
|
||||||
import kr.co.vividnext.sodalive.chat.character.service.ChatCharacterBannerService
|
import kr.co.vividnext.sodalive.chat.character.service.ChatCharacterBannerService
|
||||||
|
@ -137,7 +138,7 @@ class ChatCharacterController(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val relationships = character.relationships.map { it.relationShip }
|
val relationships = character.relationships.map { CharacterRelationshipResponse(it.name, it.relationShip) }
|
||||||
|
|
||||||
// 응답 생성
|
// 응답 생성
|
||||||
ApiResponse.ok(
|
ApiResponse.ok(
|
||||||
|
|
|
@ -14,7 +14,7 @@ data class CharacterDetailResponse(
|
||||||
val memories: List<CharacterMemoryResponse> = emptyList(),
|
val memories: List<CharacterMemoryResponse> = emptyList(),
|
||||||
val personalities: List<CharacterPersonalityResponse> = emptyList(),
|
val personalities: List<CharacterPersonalityResponse> = emptyList(),
|
||||||
val backgrounds: List<CharacterBackgroundResponse> = emptyList(),
|
val backgrounds: List<CharacterBackgroundResponse> = emptyList(),
|
||||||
val relationships: List<String> = emptyList(),
|
val relationships: List<CharacterRelationshipResponse> = emptyList(),
|
||||||
val tags: List<String> = emptyList(),
|
val tags: List<String> = emptyList(),
|
||||||
val values: List<String> = emptyList(),
|
val values: List<String> = emptyList(),
|
||||||
val hobbies: List<String> = emptyList(),
|
val hobbies: List<String> = emptyList(),
|
||||||
|
@ -36,3 +36,8 @@ data class CharacterBackgroundResponse(
|
||||||
val topic: String,
|
val topic: String,
|
||||||
val description: String
|
val description: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class CharacterRelationshipResponse(
|
||||||
|
val name: String,
|
||||||
|
val relationShip: String
|
||||||
|
)
|
||||||
|
|
|
@ -266,8 +266,8 @@ class ChatCharacterService(
|
||||||
* 캐릭터에 관계 추가
|
* 캐릭터에 관계 추가
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
fun addRelationshipToChatCharacter(chatCharacter: ChatCharacter, relationShip: String) {
|
fun addRelationshipToChatCharacter(chatCharacter: ChatCharacter, name: String, relationShip: String) {
|
||||||
chatCharacter.addRelationship(relationShip)
|
chatCharacter.addRelationship(name, relationShip)
|
||||||
saveChatCharacter(chatCharacter)
|
saveChatCharacter(chatCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ class ChatCharacterService(
|
||||||
memories: List<Triple<String, String, String>> = emptyList(),
|
memories: List<Triple<String, String, String>> = emptyList(),
|
||||||
personalities: List<Pair<String, String>> = emptyList(),
|
personalities: List<Pair<String, String>> = emptyList(),
|
||||||
backgrounds: List<Pair<String, String>> = emptyList(),
|
backgrounds: List<Pair<String, String>> = emptyList(),
|
||||||
relationships: List<String> = emptyList()
|
relationships: List<Pair<String, String>> = emptyList()
|
||||||
): ChatCharacter {
|
): ChatCharacter {
|
||||||
val chatCharacter = createChatCharacter(
|
val chatCharacter = createChatCharacter(
|
||||||
characterUUID, name, description, systemPrompt, age, gender, mbti,
|
characterUUID, name, description, systemPrompt, age, gender, mbti,
|
||||||
|
@ -313,8 +313,8 @@ class ChatCharacterService(
|
||||||
chatCharacter.addBackground(topic, description)
|
chatCharacter.addBackground(topic, description)
|
||||||
}
|
}
|
||||||
|
|
||||||
relationships.forEach { relationShip ->
|
relationships.forEach { (name, relationShip) ->
|
||||||
chatCharacter.addRelationship(relationShip)
|
chatCharacter.addRelationship(name, relationShip)
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveChatCharacter(chatCharacter)
|
return saveChatCharacter(chatCharacter)
|
||||||
|
@ -412,7 +412,7 @@ class ChatCharacterService(
|
||||||
if (request.relationships != null) {
|
if (request.relationships != null) {
|
||||||
chatCharacter.relationships.clear()
|
chatCharacter.relationships.clear()
|
||||||
request.relationships.forEach { relationship ->
|
request.relationships.forEach { relationship ->
|
||||||
chatCharacter.addRelationship(relationship)
|
chatCharacter.addRelationship(relationship.name, relationship.relationShip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue