-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from Chat-Your-Way/v4_ws
V4 ws
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ on: | |
push: | ||
branches: | ||
- v3 | ||
pull_request: | ||
branches: | ||
- v3 | ||
|
||
permissions: | ||
contents: read | ||
|
37 changes: 37 additions & 0 deletions
37
src/main/java/com/chat/yourway/controller/websocket/ChatController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.chat.yourway.controller.websocket; | ||
|
||
|
||
import com.chat.yourway.dto.request.MessageRequestDto; | ||
import com.chat.yourway.dto.response.MessageResponseDto; | ||
import com.chat.yourway.service.MessageService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Controller; | ||
|
||
import java.util.UUID; | ||
|
||
@Controller | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ChatController { | ||
|
||
private final SimpMessagingTemplate messagingTemplate; | ||
private final MessageService messageService; | ||
|
||
@MessageMapping("/app/topic/public/{topicId}") | ||
public MessageResponseDto sendMessage(@DestinationVariable UUID topicId, MessageRequestDto message) { | ||
|
||
log.info("Received message for topic ID: {}", topicId); | ||
|
||
MessageResponseDto sendMessage = messageService.sendToTopic(topicId, message); | ||
log.info("Message was saved in DB"); | ||
|
||
messagingTemplate.convertAndSend("/topic/public/" + topicId, message); | ||
log.info("Message sent to topic ID: {}", topicId) ; | ||
|
||
return sendMessage; | ||
} | ||
} |