diff --git a/src/main/java/io/urdego/urdego_game_service/domain/game/service/GameServiceImpl.java b/src/main/java/io/urdego/urdego_game_service/domain/game/service/GameServiceImpl.java index f980578..a73430f 100644 --- a/src/main/java/io/urdego/urdego_game_service/domain/game/service/GameServiceImpl.java +++ b/src/main/java/io/urdego/urdego_game_service/domain/game/service/GameServiceImpl.java @@ -16,12 +16,14 @@ import io.urdego.urdego_game_service.domain.round.entity.Question; import io.urdego.urdego_game_service.domain.round.service.RoundService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.Instant; import java.util.*; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -76,6 +78,8 @@ public ScoreRes giveScores(ScoreReq request) { gameRepository.save(game); + log.info("게임 점수 정보 : roundScores={}, totalScores={}", game.getRoundScores(), game.getTotalScores()); + return ScoreRes.from(game); } @@ -119,6 +123,8 @@ public Game findGameById(String gameId) { game.setTotalScores(new HashMap<>()); } + gameRepository.save(game); + return game; } @@ -126,16 +132,21 @@ public Game findGameById(String gameId) { private void updateRoundScores(Game game, int roundNum, List answers) { Map> roundScores = game.getRoundScores(); - if (!roundScores.containsKey(roundNum)) { - roundScores.put(roundNum, new HashMap<>()); + if (roundScores == null) { + roundScores = new HashMap<>(); } + roundScores.putIfAbsent(roundNum, new HashMap<>()); + Map roundScore = roundScores.get(roundNum); for (Answer answer : answers) { + log.info("Answer: userId={}, score={}", answer.getUserId(), answer.getScore()); roundScore.put(answer.getUserId(), answer.getScore()); } game.setRoundScores(roundScores); + + log.info("{}라운드 점수가 업데이트 되었습니다. : {}", roundNum, game.getRoundScores()); } // 전체 점수 업뎃 @@ -149,5 +160,7 @@ private void updateTotalScores(Game game) { }); game.setTotalScores(totalScores); + + log.info("전체 점수가 업데이트 되었습니다. : {}", game.getTotalScores()); } } diff --git a/src/main/java/io/urdego/urdego_game_service/domain/round/entity/Answer.java b/src/main/java/io/urdego/urdego_game_service/domain/round/entity/Answer.java index 7e87b86..6010139 100644 --- a/src/main/java/io/urdego/urdego_game_service/domain/round/entity/Answer.java +++ b/src/main/java/io/urdego/urdego_game_service/domain/round/entity/Answer.java @@ -6,6 +6,7 @@ import lombok.NoArgsConstructor; import org.springframework.data.annotation.Id; import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.redis.core.index.Indexed; @Getter @RedisHash(value = "answer", timeToLive = 3600) @@ -14,7 +15,10 @@ public class Answer { @Id private String answerId; + + @Indexed private String questionId; + private String userId; private double latitude; private double longitude; diff --git a/src/main/java/io/urdego/urdego_game_service/domain/round/repository/AnswerRepository.java b/src/main/java/io/urdego/urdego_game_service/domain/round/repository/AnswerRepository.java index 2906e53..6902f12 100644 --- a/src/main/java/io/urdego/urdego_game_service/domain/round/repository/AnswerRepository.java +++ b/src/main/java/io/urdego/urdego_game_service/domain/round/repository/AnswerRepository.java @@ -8,5 +8,5 @@ @Repository public interface AnswerRepository extends CrudRepository { - List findByQuestionId(String questionId); + List findAllByQuestionId(String questionId); } diff --git a/src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundServiceImpl.java b/src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundServiceImpl.java index 6b82c76..8900171 100644 --- a/src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundServiceImpl.java +++ b/src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundServiceImpl.java @@ -117,7 +117,7 @@ public AnswerRes submitAnswer(AnswerReq request) { @Override @Transactional(readOnly = true) public List findAnswersByQuestionId(String questionId) { - return answerRepository.findByQuestionId(questionId); + return answerRepository.findAllByQuestionId(questionId); } // roomId로 문제 정보 조회