From 124e8a9fdd29cd41f5ef9338f2e7d636793a05b7 Mon Sep 17 00:00:00 2001 From: sehee Date: Wed, 16 Jul 2025 14:40:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:recycle:=20=EC=BB=A4=EC=8A=A4=ED=85=80=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/domain/game/app/RoomService.java | 27 +++++++++---------- .../config/StompChannelInterceptor.java | 22 +++++++-------- .../exception/errorcode/RoomErrorCode.java | 3 ++- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java b/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java index 27c1522c..507fc32e 100644 --- a/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java +++ b/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java @@ -31,19 +31,17 @@ import io.f1.backend.domain.game.store.RoomRepository; import io.f1.backend.domain.quiz.app.QuizService; import io.f1.backend.domain.quiz.entity.Quiz; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import org.hibernate.boot.model.naming.IllegalIdentifierException; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; - +import io.f1.backend.global.exception.CustomException; +import io.f1.backend.global.exception.errorcode.RoomErrorCode; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; @Slf4j @Service @@ -91,18 +89,18 @@ public void enterRoom(RoomValidationRequest request) { Room room = findRoom(request.roomId()); if (room.getState().equals(RoomState.PLAYING)) { - throw new IllegalArgumentException("403 게임이 진행중입니다."); + throw new CustomException(RoomErrorCode.ROOM_GAME_IN_PROGRESS); } int maxUserCnt = room.getRoomSetting().maxUserCount(); int currentCnt = room.getUserIdSessionMap().size(); if (maxUserCnt == currentCnt) { - throw new IllegalArgumentException("403 정원이 모두 찼습니다."); + throw new CustomException(RoomErrorCode.ROOM_USER_LIMIT_REACHED); } if (room.getRoomSetting().locked() && !room.getRoomSetting().password().equals(request.password())) { - throw new IllegalArgumentException("401 비밀번호가 일치하지 않습니다."); + throw new CustomException(RoomErrorCode.WRONG_PASSWORD); } room.getUserIdSessionMap().put(getCurrentUserId(), PENDING_SESSION_ID); @@ -201,7 +199,7 @@ private Player getRemovePlayer(Room room, String sessionId) { Player removePlayer = room.getPlayerSessionMap().get(sessionId); if (removePlayer == null) { room.removeUserId(getCurrentUserId()); - throw new IllegalIdentifierException("404 세션 없음 비정상적인 퇴장 요청"); + throw new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND); } return removePlayer; } @@ -217,7 +215,7 @@ private Player createPlayer() { private Room findRoom(Long roomId) { return roomRepository .findRoom(roomId) - .orElseThrow(() -> new IllegalArgumentException("404 존재하지 않는 방입니다.")); + .orElseThrow(() -> new CustomException(RoomErrorCode.ROOM_NOT_FOUND)); } private boolean isLastPlayer(Room room, String sessionId) { @@ -245,8 +243,7 @@ private void changeHost(Room room, String hostSessionId) { playerSessionMap.get( nextHostSessionId.orElseThrow( () -> - new IllegalArgumentException( - "방장 교체 불가 - 404 해당 세션 플레이어는 존재하지않습니다."))); + new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND))); room.updateHost(nextHost); log.info("user_id:{} 방장 변경 완료 ", nextHost.getId()); diff --git a/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java b/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java index 4a89c04c..d49eb4c5 100644 --- a/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java +++ b/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java @@ -27,20 +27,16 @@ public Message preSend(Message message, MessageChannel channel) { throw new IllegalArgumentException("Stomp command required"); } - switch (command) { - case CONNECT -> log.info("CONNECT : 세션 연결 - sessionId = {}", sessionId); - - case SUBSCRIBE -> { - if (destination != null && sessionId != null) { - log.info("SUBSCRIBE : 구독 시작 destination = {}", destination); - } + if(command.equals(StompCommand.CONNECT)) { + log.info("CONNECT : 세션 연결 - sessionId = {}", sessionId); + }else if(command.equals(StompCommand.SUBSCRIBE)) { + if (destination != null && sessionId != null) { + log.info("SUBSCRIBE : 구독 시작 destination = {}", destination); } - - case SEND -> log.info("SEND : 요청 destination = {}", destination); - - case DISCONNECT -> log.info("DISCONNECT : 연결 해제 sessionId = {}", sessionId); - - default -> throw new IllegalStateException("Unexpected command: " + command); + }else if(command.equals(StompCommand.SEND)) { + log.info("SEND : 요청 destination = {}", destination); + }else if(command.equals(StompCommand.DISCONNECT)) { + log.info("DISCONNECT : 연결 해제 sessionId = {}", sessionId); } return message; diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java index 191147ac..b9e67c2a 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java @@ -11,7 +11,8 @@ public enum RoomErrorCode implements ErrorCode { ROOM_USER_LIMIT_REACHED("E403002", HttpStatus.FORBIDDEN, "정원이 모두 찼습니다."), ROOM_GAME_IN_PROGRESS("E403003", HttpStatus.FORBIDDEN, "게임이 진행 중 입니다."), ROOM_NOT_FOUND("E404005", HttpStatus.NOT_FOUND, "존재하지 않는 방입니다."), - WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다."); + WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다."), + SOCKET_SESSION_NOT_FOUND("E404006",HttpStatus.NOT_FOUND,"존재하지 않는 소켓 세션입니다."); private final String code; From 390b8e69ce536f70a55a2bbd7378b7720e10430e Mon Sep 17 00:00:00 2001 From: github-actions <> Date: Wed, 16 Jul 2025 05:40:19 +0000 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20Java=20=EC=8A=A4=ED=83=80=EC=9D=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/f1/backend/domain/game/app/RoomService.java | 14 ++++++++------ .../global/config/StompChannelInterceptor.java | 8 ++++---- .../global/exception/errorcode/RoomErrorCode.java | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java b/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java index 507fc32e..9e289b20 100644 --- a/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java +++ b/backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java @@ -33,15 +33,18 @@ import io.f1.backend.domain.quiz.entity.Quiz; import io.f1.backend.global.exception.CustomException; import io.f1.backend.global.exception.errorcode.RoomErrorCode; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; + import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; @Slf4j @Service @@ -242,8 +245,7 @@ private void changeHost(Room room, String hostSessionId) { Player nextHost = playerSessionMap.get( nextHostSessionId.orElseThrow( - () -> - new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND))); + () -> new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND))); room.updateHost(nextHost); log.info("user_id:{} 방장 변경 완료 ", nextHost.getId()); diff --git a/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java b/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java index d49eb4c5..dea375a8 100644 --- a/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java +++ b/backend/src/main/java/io/f1/backend/global/config/StompChannelInterceptor.java @@ -27,15 +27,15 @@ public Message preSend(Message message, MessageChannel channel) { throw new IllegalArgumentException("Stomp command required"); } - if(command.equals(StompCommand.CONNECT)) { + if (command.equals(StompCommand.CONNECT)) { log.info("CONNECT : 세션 연결 - sessionId = {}", sessionId); - }else if(command.equals(StompCommand.SUBSCRIBE)) { + } else if (command.equals(StompCommand.SUBSCRIBE)) { if (destination != null && sessionId != null) { log.info("SUBSCRIBE : 구독 시작 destination = {}", destination); } - }else if(command.equals(StompCommand.SEND)) { + } else if (command.equals(StompCommand.SEND)) { log.info("SEND : 요청 destination = {}", destination); - }else if(command.equals(StompCommand.DISCONNECT)) { + } else if (command.equals(StompCommand.DISCONNECT)) { log.info("DISCONNECT : 연결 해제 sessionId = {}", sessionId); } diff --git a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java index b9e67c2a..0626fab0 100644 --- a/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java +++ b/backend/src/main/java/io/f1/backend/global/exception/errorcode/RoomErrorCode.java @@ -12,7 +12,7 @@ public enum RoomErrorCode implements ErrorCode { ROOM_GAME_IN_PROGRESS("E403003", HttpStatus.FORBIDDEN, "게임이 진행 중 입니다."), ROOM_NOT_FOUND("E404005", HttpStatus.NOT_FOUND, "존재하지 않는 방입니다."), WRONG_PASSWORD("E401006", HttpStatus.UNAUTHORIZED, "비밀번호가 일치하지않습니다."), - SOCKET_SESSION_NOT_FOUND("E404006",HttpStatus.NOT_FOUND,"존재하지 않는 소켓 세션입니다."); + SOCKET_SESSION_NOT_FOUND("E404006", HttpStatus.NOT_FOUND, "존재하지 않는 소켓 세션입니다."); private final String code;