Skip to content

Commit

Permalink
[#33] fix: fixed code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeuk520 committed Sep 22, 2024
1 parent 16b89fe commit 7db05ef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequiredArgsConstructor
public class WebSocketController {
Expand All @@ -21,7 +23,7 @@ public class WebSocketController {
public void sendMessage(@DestinationVariable(value = "course_id") Long courseId,
SimpMessageHeaderAccessor accessor,
@Payload ChatMessageRequest request) {
Long memberId = Long.parseLong(accessor.getSessionAttributes().get("memberId").toString());
Long memberId = Long.parseLong(Objects.requireNonNull(accessor.getSessionAttributes()).get("memberId").toString());
SaveMessageResponse saveMessageResponse = chatService.saveMessage(memberId, courseId, request.message());
simpleMessageSendingOperations.convertAndSend("/topic/chat/" + courseId, saveMessageResponse);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ku/covigator/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class ChatService {

public List<Chat> getChatHistory(Long courseId) {

courseRepository.findById(courseId).orElseThrow(NotFoundCourseException::new);
return chatRepository.findChatByCourseIdOrderByTimestampAsc(courseId);
Course course = courseRepository.findById(courseId).orElseThrow(NotFoundCourseException::new);
return chatRepository.findChatByCourseIdOrderByTimestampAsc(course.getId());
}

public SaveMessageResponse saveMessage(Long memberId, Long courseId, String message) {
Expand Down

0 comments on commit 7db05ef

Please sign in to comment.