feat(admin-character): 캐릭터 수정 API
- 가치관, 취미, 목표가 중복 매핑이 되지 않도록 수정
This commit is contained in:
parent
eed755fd11
commit
147b8b0a42
|
@ -75,13 +75,13 @@ class ChatCharacter(
|
|||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true)
|
||||
var tagMappings: MutableList<ChatCharacterTagMapping> = mutableListOf()
|
||||
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true)
|
||||
var valueMappings: MutableList<ChatCharacterValueMapping> = mutableListOf()
|
||||
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true)
|
||||
var hobbyMappings: MutableList<ChatCharacterHobbyMapping> = mutableListOf()
|
||||
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
|
||||
@OneToMany(mappedBy = "chatCharacter", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true)
|
||||
var goalMappings: MutableList<ChatCharacterGoalMapping> = mutableListOf()
|
||||
|
||||
// 태그 추가 헬퍼 메소드
|
||||
|
|
|
@ -172,6 +172,66 @@ class ChatCharacterService(
|
|||
goals.forEach { addGoalToCharacter(chatCharacter, it) }
|
||||
}
|
||||
|
||||
/**
|
||||
* 가치관 매핑 증분 업데이트
|
||||
*/
|
||||
@Transactional
|
||||
fun updateValuesForCharacter(chatCharacter: ChatCharacter, values: List<String>) {
|
||||
val desired = values.distinct()
|
||||
val current = chatCharacter.valueMappings.map { it.value.value }
|
||||
val toAdd = desired.filterNot { current.contains(it) }
|
||||
toAdd.forEach { addValueToCharacter(chatCharacter, it) }
|
||||
if (chatCharacter.valueMappings.isNotEmpty()) {
|
||||
val iterator = chatCharacter.valueMappings.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val mapping = iterator.next()
|
||||
if (!desired.contains(mapping.value.value)) {
|
||||
iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 취미 매핑 증분 업데이트
|
||||
*/
|
||||
@Transactional
|
||||
fun updateHobbiesForCharacter(chatCharacter: ChatCharacter, hobbies: List<String>) {
|
||||
val desired = hobbies.distinct()
|
||||
val current = chatCharacter.hobbyMappings.map { it.hobby.hobby }
|
||||
val toAdd = desired.filterNot { current.contains(it) }
|
||||
toAdd.forEach { addHobbyToCharacter(chatCharacter, it) }
|
||||
if (chatCharacter.hobbyMappings.isNotEmpty()) {
|
||||
val iterator = chatCharacter.hobbyMappings.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val mapping = iterator.next()
|
||||
if (!desired.contains(mapping.hobby.hobby)) {
|
||||
iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 목표 매핑 증분 업데이트
|
||||
*/
|
||||
@Transactional
|
||||
fun updateGoalsForCharacter(chatCharacter: ChatCharacter, goals: List<String>) {
|
||||
val desired = goals.distinct()
|
||||
val current = chatCharacter.goalMappings.map { it.goal.goal }
|
||||
val toAdd = desired.filterNot { current.contains(it) }
|
||||
toAdd.forEach { addGoalToCharacter(chatCharacter, it) }
|
||||
if (chatCharacter.goalMappings.isNotEmpty()) {
|
||||
val iterator = chatCharacter.goalMappings.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val mapping = iterator.next()
|
||||
if (!desired.contains(mapping.goal.goal)) {
|
||||
iterator.remove() // orphanRemoval=true 이므로 매핑 엔티티 삭제 처리
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐릭터 저장
|
||||
*/
|
||||
|
@ -441,18 +501,15 @@ class ChatCharacterService(
|
|||
}
|
||||
|
||||
if (request.values != null) {
|
||||
chatCharacter.valueMappings.clear()
|
||||
addValuesToCharacter(chatCharacter, request.values)
|
||||
updateValuesForCharacter(chatCharacter, request.values)
|
||||
}
|
||||
|
||||
if (request.hobbies != null) {
|
||||
chatCharacter.hobbyMappings.clear()
|
||||
addHobbiesToCharacter(chatCharacter, request.hobbies)
|
||||
updateHobbiesForCharacter(chatCharacter, request.hobbies)
|
||||
}
|
||||
|
||||
if (request.goals != null) {
|
||||
chatCharacter.goalMappings.clear()
|
||||
addGoalsToCharacter(chatCharacter, request.goals)
|
||||
updateGoalsForCharacter(chatCharacter, request.goals)
|
||||
}
|
||||
|
||||
// 추가 정보 설정 - 변경된 데이터만 업데이트
|
||||
|
|
Loading…
Reference in New Issue