Skip to content

Commit

Permalink
Merge pull request #120 from fourix4/feat/chat
Browse files Browse the repository at this point in the history
[#39] refactor : Message 생성 로직 수정
  • Loading branch information
TaeHoon0 authored Jul 24, 2024
2 parents 76dd74b + 2f98728 commit 2941570
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/example/CatchStudy/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ public List<MessageResponseDto> 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));

Expand Down

0 comments on commit 2941570

Please sign in to comment.