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;