From ca27903e45778c729df5eed6506d988bfc74dad2 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 20 Aug 2025 15:39:52 +0900 Subject: [PATCH] =?UTF-8?q?fix(character-comment):=20=EC=BA=90=EB=A6=AD?= =?UTF-8?q?=ED=84=B0=20=EC=83=81=EC=84=B8=20=EB=8C=93=EA=B8=80=20=EC=A7=91?= =?UTF-8?q?=EA=B3=84=20=EB=B0=8F=20=EC=B5=9C=EC=8B=A0=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EC=A4=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 최신 댓글 조회 시 원댓글(Parent=null)만 대상으로 조회하도록 Repository 메서드 및 Service 로직 변경 - 총 댓글 수를 "활성 원댓글 + 활성 부모를 가진 활성 답글"로 계산하여, 삭제된 원댓글의 답글은 집계에서 제외되도록 수정 --- .../character/comment/CharacterCommentRepository.kt | 12 +++++++++--- .../character/comment/CharacterCommentService.kt | 13 ++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentRepository.kt index d921a06..7f12ea8 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentRepository.kt @@ -25,8 +25,14 @@ interface CharacterCommentRepository : JpaRepository { pageable: Pageable ): List - fun findFirstByChatCharacter_IdAndIsActiveTrueOrderByCreatedAtDesc(chatCharacterId: Long): CharacterComment? + // 최신 원댓글만 조회 + fun findFirstByChatCharacter_IdAndIsActiveTrueAndParentIsNullOrderByCreatedAtDesc( + chatCharacterId: Long + ): CharacterComment? - // 전체(상위+답글) 활성 댓글 총 개수 - fun countByChatCharacter_IdAndIsActiveTrue(chatCharacterId: Long): Int + // 활성 원댓글 수 + fun countByChatCharacter_IdAndIsActiveTrueAndParentIsNull(chatCharacterId: Long): Int + + // 활성 부모를 가진 활성 답글 수 (부모가 null인 경우 제외됨) + fun countByChatCharacter_IdAndIsActiveTrueAndParent_IsActiveTrue(chatCharacterId: Long): Int } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentService.kt index ecf6234..25d186a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/comment/CharacterCommentService.kt @@ -153,13 +153,20 @@ class CharacterCommentService( @Transactional(readOnly = true) fun getLatestComment(imageHost: String, characterId: Long): CharacterCommentResponse? { - val last = commentRepository.findFirstByChatCharacter_IdAndIsActiveTrueOrderByCreatedAtDesc(characterId) - return last?.let { toCommentResponse(imageHost, it) } + return commentRepository + .findFirstByChatCharacter_IdAndIsActiveTrueAndParentIsNullOrderByCreatedAtDesc(characterId) + ?.let { toCommentResponse(imageHost, it) } } @Transactional(readOnly = true) fun getTotalCommentCount(characterId: Long): Int { - return commentRepository.countByChatCharacter_IdAndIsActiveTrue(characterId) + // 활성 원댓글 수 + 활성 부모를 가진 활성 답글 수 + val originalCount = commentRepository + .countByChatCharacter_IdAndIsActiveTrueAndParentIsNull(characterId) + val replyWithActiveParentCount = commentRepository + .countByChatCharacter_IdAndIsActiveTrueAndParent_IsActiveTrue(characterId) + + return originalCount + replyWithActiveParentCount } @Transactional