diff --git a/src/main/java/com/example/CatchStudy/controller/MessageController.java b/src/main/java/com/example/CatchStudy/controller/MessageController.java index cdd3bf4..f3549b5 100644 --- a/src/main/java/com/example/CatchStudy/controller/MessageController.java +++ b/src/main/java/com/example/CatchStudy/controller/MessageController.java @@ -10,6 +10,8 @@ import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.web.bind.annotation.RestController; +import java.security.Principal; + @RestController @RequiredArgsConstructor public class MessageController { @@ -18,7 +20,8 @@ public class MessageController { @MessageMapping("/{chatRoomId}/chat") @SendTo("/sub/{chatRoomId}/chat") - public void createMessage(@DestinationVariable long chatRoomId, MessageRequestDto messageRequestDto) { - MessageResponseDto messageResponseDto = chatService.createMessage(chatRoomId, messageRequestDto); + public void createMessage(@DestinationVariable long chatRoomId, MessageRequestDto messageRequestDto, Principal principal) { + String email = principal.getName(); + MessageResponseDto messageResponseDto = chatService.createMessage(chatRoomId, messageRequestDto, email); } } diff --git a/src/main/java/com/example/CatchStudy/service/ChatService.java b/src/main/java/com/example/CatchStudy/service/ChatService.java index 0779742..39eb85a 100644 --- a/src/main/java/com/example/CatchStudy/service/ChatService.java +++ b/src/main/java/com/example/CatchStudy/service/ChatService.java @@ -87,10 +87,9 @@ public List getMessageList(long chatRoomId) { } @Transactional - public MessageResponseDto createMessage(long chatRoomId, MessageRequestDto messageRequestDto) { + public MessageResponseDto createMessage(long chatRoomId, MessageRequestDto messageRequestDto, String email) { - Users user = usersRepository.findByUserId(usersService.getCurrentUserId()). - orElseThrow(() -> new CatchStudyException(ErrorCode.USER_NOT_FOUND)); + Users user = usersRepository.findByEmail(email); ChatRoom chatRoom = chatRoomRepository.findById(chatRoomId). orElseThrow(() -> new CatchStudyException(ErrorCode.CHATROOM_NOT_FOUND));