From d016a51b5de0128e68217c348ff2db736c3f8374 Mon Sep 17 00:00:00 2001 From: HYH0804 Date: Wed, 27 May 2026 21:50:01 +0900 Subject: [PATCH] =?UTF-8?q?#250=20[Fix]=20=ED=88=AC=ED=91=9C=20=EB=B9=84?= =?UTF-8?q?=EC=9C=A8=20=EA=B3=84=EC=82=B0=20=EA=B8=B0=EC=A4=80=EC=9D=84=20?= =?UTF-8?q?preVoteOption=EC=97=90=EC=84=9C=20postVoteOption=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- .../picke/domain/vote/repository/BattleVoteRepository.java | 4 ++++ .../swyp/picke/domain/vote/service/BattleVoteServiceImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/swyp/picke/domain/vote/repository/BattleVoteRepository.java b/src/main/java/com/swyp/picke/domain/vote/repository/BattleVoteRepository.java index 825ddcd..07bbf0b 100644 --- a/src/main/java/com/swyp/picke/domain/vote/repository/BattleVoteRepository.java +++ b/src/main/java/com/swyp/picke/domain/vote/repository/BattleVoteRepository.java @@ -27,6 +27,10 @@ public interface BattleVoteRepository extends JpaRepository { long countByBattleAndPreVoteOption(Battle battle, BattleOption preVoteOption); + long countByBattleAndPostVoteOption(Battle battle, BattleOption postVoteOption); + + long countByBattleAndPostVoteOptionIsNotNull(Battle battle); + Optional findTopByBattleOrderByUpdatedAtDesc(Battle battle); @Query("SELECT v FROM BattleVote v JOIN FETCH v.battle JOIN FETCH v.preVoteOption " + diff --git a/src/main/java/com/swyp/picke/domain/vote/service/BattleVoteServiceImpl.java b/src/main/java/com/swyp/picke/domain/vote/service/BattleVoteServiceImpl.java index 6f62f00..1b13289 100644 --- a/src/main/java/com/swyp/picke/domain/vote/service/BattleVoteServiceImpl.java +++ b/src/main/java/com/swyp/picke/domain/vote/service/BattleVoteServiceImpl.java @@ -75,11 +75,11 @@ public Long findPostVoteOptionId(Long battleId, Long userId) { public VoteStatsResponse getVoteStats(Long battleId) { Battle battle = battleService.findById(battleId); List options = battleOptionRepository.findByBattle(battle); - long totalCount = battleVoteRepository.countByBattle(battle); + long totalCount = battleVoteRepository.countByBattleAndPostVoteOptionIsNotNull(battle); List stats = options.stream() .map(option -> { - long count = battleVoteRepository.countByBattleAndPreVoteOption(battle, option); + long count = battleVoteRepository.countByBattleAndPostVoteOption(battle, option); double ratio = totalCount > 0 ? Math.round((double) count / totalCount * 1000.0) / 10.0 : 0.0;