Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public interface BattleVoteRepository extends JpaRepository<BattleVote, Long> {

long countByBattleAndPreVoteOption(Battle battle, BattleOption preVoteOption);

long countByBattleAndPostVoteOption(Battle battle, BattleOption postVoteOption);

long countByBattleAndPostVoteOptionIsNotNull(Battle battle);

Optional<BattleVote> findTopByBattleOrderByUpdatedAtDesc(Battle battle);

@Query("SELECT v FROM BattleVote v JOIN FETCH v.battle JOIN FETCH v.preVoteOption " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public Long findPostVoteOptionId(Long battleId, Long userId) {
public VoteStatsResponse getVoteStats(Long battleId) {
Battle battle = battleService.findById(battleId);
List<BattleOption> options = battleOptionRepository.findByBattle(battle);
long totalCount = battleVoteRepository.countByBattle(battle);
long totalCount = battleVoteRepository.countByBattleAndPostVoteOptionIsNotNull(battle);

List<VoteStatsResponse.OptionStat> 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;
Expand Down