diff --git a/src/main/java/org/ezcode/codetest/application/chatting/service/ChattingUseCase.java b/src/main/java/org/ezcode/codetest/application/chatting/service/ChattingUseCase.java index 21a3fb3a..7b15d211 100644 --- a/src/main/java/org/ezcode/codetest/application/chatting/service/ChattingUseCase.java +++ b/src/main/java/org/ezcode/codetest/application/chatting/service/ChattingUseCase.java @@ -56,7 +56,7 @@ public void removeChatRoom(ChatRoomDeleteRequest request, String email) { ChatRoom removedRoom = chattingDomainService.getChatRoom(request.roomId()); - chattingDomainService.isChatRoomOwner(removedRoom, user.getId()); + chattingDomainService.checkChatRoomOwnerOrAdmin(removedRoom, user); chattingDomainService.removeChatRoom(removedRoom); diff --git a/src/main/java/org/ezcode/codetest/application/game/management/GameAdminUseCase.java b/src/main/java/org/ezcode/codetest/application/game/management/GameAdminUseCase.java index 863c3020..f2740b16 100644 --- a/src/main/java/org/ezcode/codetest/application/game/management/GameAdminUseCase.java +++ b/src/main/java/org/ezcode/codetest/application/game/management/GameAdminUseCase.java @@ -20,6 +20,7 @@ import org.ezcode.codetest.domain.game.model.item.Item; import org.ezcode.codetest.domain.game.model.skill.Skill; import org.ezcode.codetest.domain.game.service.GameManagementDomainService; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,6 +28,7 @@ @Service @RequiredArgsConstructor +@PreAuthorize("hasRole('ADMIN')") public class GameAdminUseCase { private final GameManagementDomainService managementService; diff --git a/src/main/java/org/ezcode/codetest/domain/chat/repository/ChatRepository.java b/src/main/java/org/ezcode/codetest/domain/chat/repository/ChatRepository.java index d0640edb..bbdfc2d1 100644 --- a/src/main/java/org/ezcode/codetest/domain/chat/repository/ChatRepository.java +++ b/src/main/java/org/ezcode/codetest/domain/chat/repository/ChatRepository.java @@ -8,8 +8,6 @@ public interface ChatRepository { Chat save(Chat chat); - List findAll(); - List findChatsFromLastHour(Long roomId); } diff --git a/src/main/java/org/ezcode/codetest/domain/chat/service/ChattingDomainService.java b/src/main/java/org/ezcode/codetest/domain/chat/service/ChattingDomainService.java index 4df285af..c2b33a08 100644 --- a/src/main/java/org/ezcode/codetest/domain/chat/service/ChattingDomainService.java +++ b/src/main/java/org/ezcode/codetest/domain/chat/service/ChattingDomainService.java @@ -8,6 +8,8 @@ import org.ezcode.codetest.domain.chat.model.ChatRoom; import org.ezcode.codetest.domain.chat.repository.ChatRepository; import org.ezcode.codetest.domain.chat.repository.ChatRoomRepository; +import org.ezcode.codetest.domain.user.model.entity.User; +import org.ezcode.codetest.domain.user.model.enums.UserRole; import org.springframework.stereotype.Component; import lombok.RequiredArgsConstructor; @@ -29,9 +31,9 @@ public void removeChatRoom(ChatRoom room) { chatRoomRepository.delete(room); } - public void isChatRoomOwner(ChatRoom room, Long userId) { + public void checkChatRoomOwnerOrAdmin(ChatRoom room, User user) { - if(!room.isOwner(userId)) { + if (!room.isOwner(user.getId()) && user.getRole() != UserRole.ADMIN) { throw new ChattingException(ChattingExceptionCode.CHATROOM_NOT_OWNER); } } diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/config/CustomHandShakeHandler.java b/src/main/java/org/ezcode/codetest/infrastructure/event/config/CustomHandShakeHandler.java index 75c5e6fe..818f66af 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/config/CustomHandShakeHandler.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/config/CustomHandShakeHandler.java @@ -28,8 +28,17 @@ protected Principal determineUser( String query = uri.getQuery(); String tokenParam = null; - if (query != null && query.startsWith("token=")) { + if (query == null) { + throw new IllegalArgumentException("WebSocket 연결에 필요한 토큰이 없습니다."); + } + + if (query.startsWith("token=")) { tokenParam = query.substring(6); + } else if (query.startsWith("chat-token=")) { + tokenParam = query.substring(11); + attributes.put("isChattingWebsocket", true); + } else { + throw new IllegalArgumentException("허용되지 않은 토큰 파라미터: " + query); } Claims claims = jwtUtil.extractClaims(tokenParam); diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/dto/GameLevelUpEvent.java b/src/main/java/org/ezcode/codetest/infrastructure/event/dto/GameLevelUpEvent.java new file mode 100644 index 00000000..9da27e48 --- /dev/null +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/dto/GameLevelUpEvent.java @@ -0,0 +1,12 @@ +package org.ezcode.codetest.infrastructure.event.dto; + +public record GameLevelUpEvent( + + Long userId, + + boolean isProblemSolved, + + String problemCategory + +) { +} diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/ChatEventListener.java b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/ChatEventListener.java index 6b0439d1..a57ac94d 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/ChatEventListener.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/ChatEventListener.java @@ -5,7 +5,7 @@ import org.ezcode.codetest.infrastructure.event.dto.ChatRoomParticipantCountChangeEvent; import org.ezcode.codetest.infrastructure.event.dto.ChatRoomEntryExitMessageEvent; import org.ezcode.codetest.infrastructure.event.dto.ChatRoomHistoryLoadEvent; -import org.ezcode.codetest.infrastructure.event.service.StompMessageService; +import org.ezcode.codetest.infrastructure.event.publisher.StompMessageService; import org.springframework.stereotype.Component; import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalEventListener; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/GameLevelUpListener.java b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/GameLevelUpListener.java new file mode 100644 index 00000000..9500a045 --- /dev/null +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/GameLevelUpListener.java @@ -0,0 +1,38 @@ +package org.ezcode.codetest.infrastructure.event.listener; + +import org.ezcode.codetest.domain.game.exception.GameException; +import org.ezcode.codetest.domain.game.service.CharacterStatusDomainService; +import org.ezcode.codetest.infrastructure.event.dto.GameLevelUpEvent; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; +import org.springframework.transaction.interceptor.TransactionAspectSupport; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@RequiredArgsConstructor +public class GameLevelUpListener { + + private final CharacterStatusDomainService characterDomainService; + + @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void handleGameCharacterLevelUp(GameLevelUpEvent event) { + + try { + characterDomainService.gameCharacterLevelUp(event.userId(), event.isProblemSolved(), + event.problemCategory()); + } catch (GameException ge) { + log.info("현재 해당 사용자는 게임 캐릭터를 생성한 상태가 아닙니다. {}", ge.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } catch (Exception e) { + log.warn("문제 풀이로 인한 레벨업 실패 Unknown Error 발생", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } + } +} diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/NotificationEventListener.java b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/NotificationEventListener.java index a8f2e655..62e37ec4 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/NotificationEventListener.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/NotificationEventListener.java @@ -7,7 +7,7 @@ import org.ezcode.codetest.application.notification.event.NotificationReadEvent; import org.ezcode.codetest.infrastructure.event.dto.NotificationRecord; import org.ezcode.codetest.infrastructure.event.dto.NotificationResponse; -import org.ezcode.codetest.infrastructure.event.service.StompMessageService; +import org.ezcode.codetest.infrastructure.event.publisher.StompMessageService; import org.ezcode.codetest.infrastructure.persistence.repository.notification.NotificationRepository; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/WebSocketEventListener.java b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/WebSocketEventListener.java index 3aa50b4d..42635c19 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/listener/WebSocketEventListener.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/listener/WebSocketEventListener.java @@ -8,7 +8,7 @@ import org.ezcode.codetest.domain.chat.model.ChatRoom; import org.ezcode.codetest.domain.chat.service.ChattingDomainService; import org.ezcode.codetest.domain.user.service.UserDomainService; -import org.ezcode.codetest.infrastructure.event.service.StompMessageService; +import org.ezcode.codetest.infrastructure.event.publisher.StompMessageService; import org.ezcode.codetest.infrastructure.session.service.RedisSessionCountService; import org.springframework.context.ApplicationListener; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; @@ -31,11 +31,24 @@ public class WebSocketEventListener implements ApplicationListener attrs = header.getSessionAttributes(); + + if (attrs == null) { + return; + } + + Boolean isChatWs = (Boolean)attrs.get("isChattingWebsocket"); + + if (!Boolean.TRUE.equals(isChatWs)) { + return; + } + try { - StompHeaderAccessor h = StompHeaderAccessor.wrap(event.getMessage()); - String sessionId = h.getSessionId(); + String sessionId = header.getSessionId(); - String email = h.getUser().getName(); + String email = header.getUser().getName(); String nickName = userDomainService.getUser(email).getNickname(); RoomSessionInfo roomData = sessionService.removeSessionCount(sessionId); @@ -51,7 +64,7 @@ public void onApplicationEvent(SessionDisconnectEvent event) { messageService.handleChatRoomEntryExitMessage(ChatMessageTemplate.CHAT_ROOM_LEFT.format(nickName), chatRoom.getId()); } catch (Exception e) { - log.info("SessionDisconnectEvent 처리 중 예외 발생, 채팅 관련 웹소켓 세션이 아닙니다.", e); + log.info("SessionDisconnectEvent 채팅 세션 정리중 예외 발생", e); } } } diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/service/ChatEventPublisher.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ChatEventPublisher.java similarity index 96% rename from src/main/java/org/ezcode/codetest/infrastructure/event/service/ChatEventPublisher.java rename to src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ChatEventPublisher.java index ab5672fa..e310291e 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/service/ChatEventPublisher.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ChatEventPublisher.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.infrastructure.event.service; +package org.ezcode.codetest.infrastructure.event.publisher; import org.ezcode.codetest.application.chatting.port.event.ChatEventService; import org.ezcode.codetest.infrastructure.event.dto.ChatMessageBroadcastEvent; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/service/DiscordNotifier.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/DiscordNotifier.java similarity index 97% rename from src/main/java/org/ezcode/codetest/infrastructure/event/service/DiscordNotifier.java rename to src/main/java/org/ezcode/codetest/infrastructure/event/publisher/DiscordNotifier.java index 95fb5176..08a0786f 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/service/DiscordNotifier.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/DiscordNotifier.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.infrastructure.event.service; +package org.ezcode.codetest.infrastructure.event.publisher; import java.time.Instant; import java.util.List; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/service/NotificationEventPublisher.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/NotificationEventPublisher.java similarity index 94% rename from src/main/java/org/ezcode/codetest/infrastructure/event/service/NotificationEventPublisher.java rename to src/main/java/org/ezcode/codetest/infrastructure/event/publisher/NotificationEventPublisher.java index 970eb931..460e1826 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/service/NotificationEventPublisher.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/NotificationEventPublisher.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.infrastructure.event.service; +package org.ezcode.codetest.infrastructure.event.publisher; import org.ezcode.codetest.application.notification.event.NotificationCreateEvent; import org.ezcode.codetest.application.notification.event.NotificationListRequestEvent; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ProblemEventPublisher.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ProblemEventPublisher.java new file mode 100644 index 00000000..094c7c59 --- /dev/null +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/ProblemEventPublisher.java @@ -0,0 +1,24 @@ +package org.ezcode.codetest.infrastructure.event.publisher; + +import org.ezcode.codetest.domain.submission.model.entity.UserProblemResult; +import org.ezcode.codetest.infrastructure.event.dto.GameLevelUpEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class ProblemEventPublisher { + + private final ApplicationEventPublisher publisher; + + public void publishProblemSolveEvent(UserProblemResult event) { + + Long userId = event.getUser().getId(); + boolean isCorrect = event.isCorrect(); + String problemCategory = event.getProblem().getCategory().getDescription(); + + publisher.publishEvent(new GameLevelUpEvent(userId, isCorrect, problemCategory)); + } +} diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/service/RedisJudgeQueueProducer.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/RedisJudgeQueueProducer.java similarity index 94% rename from src/main/java/org/ezcode/codetest/infrastructure/event/service/RedisJudgeQueueProducer.java rename to src/main/java/org/ezcode/codetest/infrastructure/event/publisher/RedisJudgeQueueProducer.java index 6dcd6286..0743efd4 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/service/RedisJudgeQueueProducer.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/RedisJudgeQueueProducer.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.infrastructure.event.service; +package org.ezcode.codetest.infrastructure.event.publisher; import java.util.Map; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/event/service/StompMessageService.java b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/StompMessageService.java similarity index 97% rename from src/main/java/org/ezcode/codetest/infrastructure/event/service/StompMessageService.java rename to src/main/java/org/ezcode/codetest/infrastructure/event/publisher/StompMessageService.java index f2b009ba..06131072 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/event/service/StompMessageService.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/event/publisher/StompMessageService.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.infrastructure.event.service; +package org.ezcode.codetest.infrastructure.event.publisher; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; diff --git a/src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/chat/ChatRepositoryImpl.java b/src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/chat/ChatRepositoryImpl.java index b53ce8ff..ee5d966e 100644 --- a/src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/chat/ChatRepositoryImpl.java +++ b/src/main/java/org/ezcode/codetest/infrastructure/persistence/repository/chat/ChatRepositoryImpl.java @@ -21,12 +21,6 @@ public Chat save(Chat chat) { return chatRepository.save(chat); } - @Override - public List findAll() { - - return chatRepository.findAll(); - } - @Override public List findChatsFromLastHour(Long roomId) { diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/config/ChatWebConfig.java b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/config/ChatWebConfig.java similarity index 70% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/config/ChatWebConfig.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/chatting/config/ChatWebConfig.java index e64b7508..4d7c5495 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/config/ChatWebConfig.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/config/ChatWebConfig.java @@ -1,6 +1,6 @@ -package org.ezcode.codetest.presentation.chattingmanagement.chatting.config; +package org.ezcode.codetest.presentation.chatting.chatting.config; -import org.ezcode.codetest.presentation.chattingmanagement.chatting.interceptor.ChatLimitInterceptor; +import org.ezcode.codetest.presentation.chatting.chatting.interceptor.ChatLimitInterceptor; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -16,6 +16,6 @@ public class ChatWebConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(chatSpamInterceptor) - .addPathPatterns("/api/room/*/chat"); + .addPathPatterns("/api/rooms/*/chat"); } } diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatController.java b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatController.java similarity index 89% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatController.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatController.java index 9e9b716f..24f42d8c 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatController.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatController.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.presentation.chattingmanagement.chatting.controller; +package org.ezcode.codetest.presentation.chatting.chatting.controller; import org.ezcode.codetest.application.chatting.dto.request.ChatSaveRequest; import org.ezcode.codetest.application.chatting.service.ChattingUseCase; @@ -14,7 +14,7 @@ import lombok.RequiredArgsConstructor; @Controller -@RequestMapping("/api/room/{roomId}/chat") +@RequestMapping("/api/rooms/{roomId}/chat") @RequiredArgsConstructor public class ChatController { diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatRoomController.java b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatRoomController.java similarity index 95% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatRoomController.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatRoomController.java index 8f4fd6b0..93b80e2a 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/controller/ChatRoomController.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/controller/ChatRoomController.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.presentation.chattingmanagement.chatting.controller; +package org.ezcode.codetest.presentation.chatting.chatting.controller; import org.ezcode.codetest.application.chatting.dto.request.ChatRoomDeleteRequest; import org.ezcode.codetest.application.chatting.dto.request.ChatRoomSaveRequest; @@ -21,7 +21,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/chatrooms") +@RequestMapping("/api/rooms") public class ChatRoomController { private final ChattingUseCase chatUseCase; diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/interceptor/ChatLimitInterceptor.java b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/interceptor/ChatLimitInterceptor.java similarity index 96% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/interceptor/ChatLimitInterceptor.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/chatting/interceptor/ChatLimitInterceptor.java index f810341c..d8747d7b 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/chatting/interceptor/ChatLimitInterceptor.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/chatting/interceptor/ChatLimitInterceptor.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.presentation.chattingmanagement.chatting.interceptor; +package org.ezcode.codetest.presentation.chatting.chatting.interceptor; import java.util.Map; diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/event/EventHandleController.java b/src/main/java/org/ezcode/codetest/presentation/chatting/event/EventHandleController.java similarity index 89% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/event/EventHandleController.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/event/EventHandleController.java index 44093d28..c50169ae 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/event/EventHandleController.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/event/EventHandleController.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.presentation.chattingmanagement.event; +package org.ezcode.codetest.presentation.chatting.event; import java.security.Principal; @@ -25,7 +25,7 @@ public void handleGetChatRoomList( chatUseCase.getChatRoomList(principal.getName(), sessionId); } - @MessageMapping("/room/{roomId}/enter") + @MessageMapping("/rooms/{roomId}/enter") public void handleGetChattingHistory( Principal principal, @DestinationVariable Long roomId, @@ -35,7 +35,7 @@ public void handleGetChattingHistory( chatUseCase.getChattingHistory(sessionId, principal.getName(), principal.getName(), roomId); } - @MessageMapping("/room/{roomId}/left") + @MessageMapping("/rooms/{roomId}/left") public void handleChatRoomLeft( Principal principal, @DestinationVariable Long roomId, diff --git a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/view/ChatViewController.java b/src/main/java/org/ezcode/codetest/presentation/chatting/view/ChatViewController.java similarity index 82% rename from src/main/java/org/ezcode/codetest/presentation/chattingmanagement/view/ChatViewController.java rename to src/main/java/org/ezcode/codetest/presentation/chatting/view/ChatViewController.java index ceb856b8..82e5ab88 100644 --- a/src/main/java/org/ezcode/codetest/presentation/chattingmanagement/view/ChatViewController.java +++ b/src/main/java/org/ezcode/codetest/presentation/chatting/view/ChatViewController.java @@ -1,4 +1,4 @@ -package org.ezcode.codetest.presentation.chattingmanagement.view; +package org.ezcode.codetest.presentation.chatting.view; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/resources/templates/chat-page.html b/src/main/resources/templates/chat-page.html index 59aed16f..e369ca8a 100644 --- a/src/main/resources/templates/chat-page.html +++ b/src/main/resources/templates/chat-page.html @@ -186,7 +186,7 @@

채팅방 목록

}); function initChat() { - const socket = new SockJS('/ws?token=' + encodeURIComponent(token)); + const socket = new SockJS('/ws?chat-token=' + encodeURIComponent(token)); stompClient = Stomp.over(socket); // ─── Heartbeat 5분(300,000ms) 설정 ─── @@ -308,7 +308,7 @@

채팅방 목록

const nr = li.dataset.roomId; if (!nr || currentRoomId === nr) return; if (chatSubscription && currentRoomId) { - stompClient.send(`/chat/room/${currentRoomId}/left`, {}, currentRoomId); + stompClient.send(`/chat/rooms/${currentRoomId}/left`, {}, currentRoomId); chatSubscription.unsubscribe(); } currentRoomId = nr; @@ -337,7 +337,7 @@

채팅방 목록

}, 100); }); setTimeout(() => { - stompClient.send(`/chat/room/${nr}/enter`, {}, nr); + stompClient.send(`/chat/rooms/${nr}/enter`, {}, nr); }, 100); }, 100); }); @@ -352,7 +352,7 @@

채팅방 목록

if (!currentRoomId) return; const m = msgInput.value.trim(); if (!m) return; - fetch(`/api/room/${currentRoomId}/chat`, { + fetch(`/api/rooms/${currentRoomId}/chat`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/test/java/org/ezcode/codetest/application/chatting/service/ChattingUseCaseTest.java b/src/test/java/org/ezcode/codetest/application/chatting/service/ChattingUseCaseTest.java index bac895cb..a7e8c757 100644 --- a/src/test/java/org/ezcode/codetest/application/chatting/service/ChattingUseCaseTest.java +++ b/src/test/java/org/ezcode/codetest/application/chatting/service/ChattingUseCaseTest.java @@ -6,7 +6,6 @@ import static org.mockito.Mockito.*; import java.util.List; -import java.util.Map; import java.util.stream.Stream; import org.ezcode.codetest.application.chatting.dto.request.ChatRoomDeleteRequest; @@ -168,7 +167,7 @@ void removeChatRoom() { // then verify(userDomainService).getUser(TEST_EMAIL); verify(chattingDomainService).getChatRoom(TEST_ROOM_ID); - verify(chattingDomainService).isChatRoomOwner(chatRoom1, user.getId()); + verify(chattingDomainService).checkChatRoomOwnerOrAdmin(chatRoom1, user); verify(chattingDomainService).removeChatRoom(chatRoom1); ArgumentCaptor cacheCaptor = ArgumentCaptor.forClass(ChatRoomCache.class); diff --git a/src/test/java/org/ezcode/codetest/domain/chat/service/ChattingDomainServiceTest.java b/src/test/java/org/ezcode/codetest/domain/chat/service/ChattingDomainServiceTest.java index 1c447b44..6bdb84f0 100644 --- a/src/test/java/org/ezcode/codetest/domain/chat/service/ChattingDomainServiceTest.java +++ b/src/test/java/org/ezcode/codetest/domain/chat/service/ChattingDomainServiceTest.java @@ -41,6 +41,7 @@ class ChattingDomainServiceTest { private ChatRoom chatRoom; private User user; + private User wrongUser; private Chat chat; private static final Long TEST_ROOM_ID = 1L; @@ -61,8 +62,19 @@ void setUp() { .age(22) .build(); + wrongUser = User.builder() + .email(TEST_EMAIL) + .username("익명2") + .password("P@ssw0rd12252") + .nickname("익명 닉네임22") + .tier(Tier.NEWBIE) + .age(22) + .build(); + ReflectionTestUtils.setField(user, "id", TEST_ROOM_ID); + ReflectionTestUtils.setField(wrongUser, "id", WRONG_USER_ID); + chatRoom = ChatRoom.builder() .title(TEMP_TITLE_1) .user(user) @@ -114,11 +126,11 @@ void isChatRoomOwner() { doReturn(true).when(chatRoom).isOwner(user.getId()); // when - chattingDomainService.isChatRoomOwner(chatRoom, user.getId()); + chattingDomainService.checkChatRoomOwnerOrAdmin(chatRoom, user); // then assertDoesNotThrow(() -> - chattingDomainService.isChatRoomOwner(chatRoom, user.getId()) + chattingDomainService.checkChatRoomOwnerOrAdmin(chatRoom, user) ); } @@ -184,7 +196,7 @@ void isChatRoomOwner() { // when ChattingException exception = assertThrows(ChattingException.class, - () -> chattingDomainService.isChatRoomOwner(chatRoom, WRONG_USER_ID)); + () -> chattingDomainService.checkChatRoomOwnerOrAdmin(chatRoom, wrongUser)); // then assertAll(