feat(creator-cheers): 팬 Talk 응원글 등록 시 언어 코드가 null인 경우 파파고 언어 감지 API를 호출하는 기능 추가

This commit is contained in:
2025-11-25 16:42:26 +09:00
parent 412c52e754
commit c5fa260a0d
2 changed files with 49 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.content
import kr.co.vividnext.sodalive.chat.character.comment.CharacterCommentRepository
import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository
import kr.co.vividnext.sodalive.explorer.profile.CreatorCheersRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpEntity
@@ -22,7 +23,8 @@ import org.springframework.web.client.RestTemplate
enum class LanguageDetectTargetType {
CONTENT,
COMMENT,
CHARACTER_COMMENT
CHARACTER_COMMENT,
CREATOR_CHEERS
}
class LanguageDetectEvent(
@@ -40,6 +42,7 @@ class LanguageDetectListener(
private val audioContentRepository: AudioContentRepository,
private val audioContentCommentRepository: AudioContentCommentRepository,
private val characterCommentRepository: CharacterCommentRepository,
private val creatorCheersRepository: CreatorCheersRepository,
@Value("\${cloud.naver.papago-client-id}")
private val papagoClientId: String,
@@ -67,6 +70,7 @@ class LanguageDetectListener(
LanguageDetectTargetType.CONTENT -> handleContentLanguageDetect(event)
LanguageDetectTargetType.COMMENT -> handleCommentLanguageDetect(event)
LanguageDetectTargetType.CHARACTER_COMMENT -> handleCharacterCommentLanguageDetect(event)
LanguageDetectTargetType.CREATOR_CHEERS -> handleCreatorCheersLanguageDetect(event)
}
}
@@ -166,6 +170,37 @@ class LanguageDetectListener(
)
}
private fun handleCreatorCheersLanguageDetect(event: LanguageDetectEvent) {
val cheersId = event.id
val cheers = creatorCheersRepository.findById(cheersId).orElse(null)
if (cheers == null) {
log.warn("[PapagoLanguageDetect] CreatorCheers not found. cheersId={}", cheersId)
return
}
// 이미 언어 코드가 설정된 경우 호출하지 않음
if (!cheers.languageCode.isNullOrBlank()) {
log.debug(
"[PapagoLanguageDetect] languageCode already set. Skip language detection. cheersId={}, languageCode={}",
cheersId,
cheers.languageCode
)
return
}
val langCode = requestPapagoLanguageCode(event.query, cheersId) ?: return
cheers.languageCode = langCode
creatorCheersRepository.save(cheers)
log.info(
"[PapagoLanguageDetect] languageCode updated from Papago. cheersId={}, langCode={}",
cheersId,
langCode
)
}
private fun requestPapagoLanguageCode(query: String, targetIdForLog: Long): String? {
return try {
val headers = HttpHeaders().apply {