Skip to content

Commit 5bb4754

Browse files
committed
BugFix(#11) : 문제 생성 관련 오류 수정, questionId key 생성값 수정(roomId + roundNum)
1 parent 66470d0 commit 5bb4754

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

src/main/java/io/urdego/urdego_game_service/controller/round/RoundSocketController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class RoundSocketController {
2121
@MessageMapping("/round/question")
2222
public void giveQuestion(QuestionReq request) {
2323
QuestionRes response = roundService.getQuestion(request);
24-
messagingTemplate.convertAndSend("game-service/sub/" + response.roomId(), response);
24+
messagingTemplate.convertAndSend("/game-service/sub/" + response.roomId(), response);
2525
}
2626

2727
// 플레이어 정답 제출

src/main/java/io/urdego/urdego_game_service/domain/game/service/GameServiceImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public GameCreateRes createGame(GameCreateReq request) {
5454

5555
// Question 생성
5656
for (int roundNum = 1; roundNum <= room.getTotalRounds(); roundNum++) {
57-
Question question = roundService.createQuestion(game.getRoomId());
57+
Question question = roundService.createQuestion(game.getRoomId(), roundNum);
5858
game.getQuestionIds().add(question.getQuestionId());
5959
}
6060

@@ -109,8 +109,17 @@ public Game updateGameStatusById(String gameId, Status status) {
109109
@Transactional(readOnly = true)
110110
@Override
111111
public Game findGameById(String gameId) {
112-
return gameRepository.findById(gameId)
112+
Game game = gameRepository.findById(gameId)
113113
.orElseThrow(() -> new GameException(ExceptionMessage.GAME_NOT_FOUND));
114+
115+
if (game.getRoundScores() == null) {
116+
game.setRoundScores(new HashMap<>());
117+
}
118+
if (game.getTotalScores() == null) {
119+
game.setTotalScores(new HashMap<>());
120+
}
121+
122+
return game;
114123
}
115124

116125
// 라운드 점수 업뎃

src/main/java/io/urdego/urdego_game_service/domain/round/entity/Question.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class Question {
2222
private List<String> contents;
2323

2424
@Builder
25-
public Question(String questionId, String roomId, int roundNum, double latitude, double longitude, String hint, List<String> contents) {
26-
this.questionId = questionId;
25+
public Question(String roomId, int roundNum, double latitude, double longitude, String hint, List<String> contents) {
26+
this.questionId = roomId + ":" + roundNum;
2727
this.roomId = roomId;
2828
this.roundNum = roundNum;
2929
this.latitude = latitude;

src/main/java/io/urdego/urdego_game_service/domain/round/repository/QuestionRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@Repository
1111
public interface QuestionRepository extends CrudRepository<Question, String> {
12-
Optional<Question> findByRoomId(String roomId);
12+
Optional<Question> findByRoomIdAndRoundNum(String roomId, int roundNum);
1313

1414
List<Question> findAllByRoomId(String roomId);
1515
}

src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public interface RoundService {
1313
// 문제 생성
14-
Question createQuestion(String roomId);
14+
Question createQuestion(String roomId, int roundNum);
1515

1616
// 문제 출제
1717
QuestionRes getQuestion(QuestionReq request);

src/main/java/io/urdego/urdego_game_service/domain/round/service/RoundServiceImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class RoundServiceImpl implements RoundService {
3535

3636
// 문제 생성
3737
@Override
38-
public Question createQuestion(String roomId) {
38+
public Question createQuestion(String roomId, int roundNum) {
3939
Room room = roomService.findRoomById(roomId);
4040

4141
// 해당 게임의 기존 문제 조회
@@ -72,7 +72,8 @@ public Question createQuestion(String roomId) {
7272
.collect(Collectors.toList());
7373

7474
newQuestion = Question.builder()
75-
.questionId(UUID.randomUUID().toString())
75+
.roomId(roomId)
76+
.roundNum(roundNum)
7677
.latitude(targetLatitude)
7778
.longitude(targetLongitude)
7879
.hint(firstContent.hint())
@@ -86,7 +87,7 @@ public Question createQuestion(String roomId) {
8687
// 문제 출제
8788
@Override
8889
public QuestionRes getQuestion(QuestionReq request) {
89-
Question question = findQuestionByRoomId(request.roomId());
90+
Question question = findQuestionByRoomIdAndRoundNum(request.roomId(), request.roundNum());
9091
return QuestionRes.from(question);
9192
}
9293

@@ -120,8 +121,9 @@ public List<Answer> findAnswersByQuestionId(String questionId) {
120121
}
121122

122123
// roomId로 문제 정보 조회
123-
private Question findQuestionByRoomId(String roomId) {
124-
return questionRepository.findByRoomId(roomId)
124+
private Question findQuestionByRoomIdAndRoundNum(String roomId, int roundNum) {
125+
String questionId = roomId + ":" + roundNum;
126+
return questionRepository.findById(questionId)
125127
.orElseThrow(() -> new QuestionException(ExceptionMessage.QUESTION_NOT_FOUND));
126128
}
127129

0 commit comments

Comments
 (0)