Skip to content

Commit 482bc72

Browse files
committed
♻️ refactor: player 조회 메서드 추가
1 parent 7c6515e commit 482bc72

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

backend/src/main/java/io/f1/backend/domain/game/app/GameService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public void handlePlayerReady(Long roomId, String sessionId) {
7878

7979
Room room = findRoom(roomId);
8080

81-
Player player = room.getPlayerSessionMap().get(sessionId);
82-
if (player == null) {
83-
throw new CustomException(RoomErrorCode.PLAYER_NOT_FOUND);
84-
}
81+
Player player = room.getPlayerBySessionId(sessionId);
8582

8683
toggleReadyIfPossible(room, player);
8784

backend/src/main/java/io/f1/backend/domain/game/model/Room.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ public boolean validateReadyStatus() {
146146
return playerSessionMap.values().stream().allMatch(Player::isReady);
147147
}
148148

149+
public Player getPlayerBySessionId(String sessionId) {
150+
Player player = playerSessionMap.get(sessionId);
151+
if (player == null) {
152+
throw new CustomException(RoomErrorCode.PLAYER_NOT_FOUND);
153+
}
154+
return player;
155+
}
156+
149157
public void resetAllPlayerReadyStates() {
150158
for (Player player : playerSessionMap.values()) {
151159
if (Objects.equals(player.getId(), getHost().getId())) continue;

0 commit comments

Comments
 (0)