From 16d94b0ac531f3caa6627a1b086956aae2848a80 Mon Sep 17 00:00:00 2001 From: Vladik Date: Wed, 4 Sep 2024 19:05:37 +0300 Subject: [PATCH 1/9] Added pull_request: v3 --- .github/workflows/deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fdc1be2..094aa45 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,6 +4,9 @@ on: push: branches: - v3 + pull_request: + branches: + - v3 permissions: contents: read From 6d91e08f4b604915b434999f7030f34c07bf35a3 Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 12 Sep 2024 20:47:22 +0300 Subject: [PATCH 2/9] ChatController and WebSocketEventListener --- .../java/com/chat/yourway/chat/ChatMessage.java | 15 +++++++++++++++ .../java/com/chat/yourway/chat/MessageType.java | 7 +++++++ .../websocket/WebSocketEventListener.java | 17 +++++++++++++++++ .../controller/websocket/ChatController.java | 17 +++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 src/main/java/com/chat/yourway/chat/ChatMessage.java create mode 100644 src/main/java/com/chat/yourway/chat/MessageType.java create mode 100644 src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java create mode 100644 src/main/java/com/chat/yourway/controller/websocket/ChatController.java diff --git a/src/main/java/com/chat/yourway/chat/ChatMessage.java b/src/main/java/com/chat/yourway/chat/ChatMessage.java new file mode 100644 index 0000000..72c2b5b --- /dev/null +++ b/src/main/java/com/chat/yourway/chat/ChatMessage.java @@ -0,0 +1,15 @@ +package com.chat.yourway.chat; + +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ChatMessage { + private String content; + private String sender; + private MessageType type; + +} diff --git a/src/main/java/com/chat/yourway/chat/MessageType.java b/src/main/java/com/chat/yourway/chat/MessageType.java new file mode 100644 index 0000000..9cbd078 --- /dev/null +++ b/src/main/java/com/chat/yourway/chat/MessageType.java @@ -0,0 +1,7 @@ +package com.chat.yourway.chat; + +public enum MessageType { + CHAT, + JOIN, + LEAVE +} diff --git a/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java b/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java new file mode 100644 index 0000000..fb614f3 --- /dev/null +++ b/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java @@ -0,0 +1,17 @@ +package com.chat.yourway.config.websocket; + + +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.messaging.SessionDisconnectEvent; + +@Component +@RequiredArgsConstructor +public class WebSocketEventListener { + + @EventListener + public void handleWebSocketDisconnectListener(SessionDisconnectEvent event){ + + } +} diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java new file mode 100644 index 0000000..9e64091 --- /dev/null +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -0,0 +1,17 @@ +package com.chat.yourway.controller.websocket; + +import com.chat.yourway.chat.ChatMessage; +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.stereotype.Controller; + +@Controller +public class ChatController { + + @MessageMapping("/chat.sendMessage") + @SendTo("/topic/public") + public ChatMessage sendMessage(@Payload ChatMessage chatMessage){ + return chatMessage; + } +} From 3c84e98b1a7bb18abf91ace821e44352a5923ca5 Mon Sep 17 00:00:00 2001 From: Lev Date: Sun, 15 Sep 2024 12:08:17 +0300 Subject: [PATCH 3/9] ChatController --- .../java/com/chat/yourway/chat/ChatMessage.java | 15 --------------- .../java/com/chat/yourway/chat/MessageType.java | 7 ------- .../websocket/WebSocketEventListener.java | 17 ----------------- .../controller/websocket/ChatController.java | 10 +--------- 4 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 src/main/java/com/chat/yourway/chat/ChatMessage.java delete mode 100644 src/main/java/com/chat/yourway/chat/MessageType.java delete mode 100644 src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java diff --git a/src/main/java/com/chat/yourway/chat/ChatMessage.java b/src/main/java/com/chat/yourway/chat/ChatMessage.java deleted file mode 100644 index 72c2b5b..0000000 --- a/src/main/java/com/chat/yourway/chat/ChatMessage.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.chat.yourway.chat; - -import lombok.*; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class ChatMessage { - private String content; - private String sender; - private MessageType type; - -} diff --git a/src/main/java/com/chat/yourway/chat/MessageType.java b/src/main/java/com/chat/yourway/chat/MessageType.java deleted file mode 100644 index 9cbd078..0000000 --- a/src/main/java/com/chat/yourway/chat/MessageType.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.chat.yourway.chat; - -public enum MessageType { - CHAT, - JOIN, - LEAVE -} diff --git a/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java b/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java deleted file mode 100644 index fb614f3..0000000 --- a/src/main/java/com/chat/yourway/config/websocket/WebSocketEventListener.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.chat.yourway.config.websocket; - - -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; -import org.springframework.web.socket.messaging.SessionDisconnectEvent; - -@Component -@RequiredArgsConstructor -public class WebSocketEventListener { - - @EventListener - public void handleWebSocketDisconnectListener(SessionDisconnectEvent event){ - - } -} diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 9e64091..10647e8 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -1,17 +1,9 @@ package com.chat.yourway.controller.websocket; -import com.chat.yourway.chat.ChatMessage; -import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.messaging.handler.annotation.SendTo; + import org.springframework.stereotype.Controller; @Controller public class ChatController { - @MessageMapping("/chat.sendMessage") - @SendTo("/topic/public") - public ChatMessage sendMessage(@Payload ChatMessage chatMessage){ - return chatMessage; - } } From a37bdf7f0d3ab3b2a5832bd94a6fadab328a17b0 Mon Sep 17 00:00:00 2001 From: Lev Date: Sun, 15 Sep 2024 12:22:34 +0300 Subject: [PATCH 4/9] ChatController --- .../controller/websocket/ChatController.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 10647e8..789186f 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -1,9 +1,24 @@ package com.chat.yourway.controller.websocket; +import com.chat.yourway.dto.response.MessageResponseDto; +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; @Controller public class ChatController { + private final SimpMessagingTemplate messagingTemplate; + + public ChatController(SimpMessagingTemplate messagingTemplate) { + this.messagingTemplate = messagingTemplate; + } + + @MessageMapping("/topic/public/{topicId}") + public void sendMessage(@DestinationVariable String topicId, MessageResponseDto message) { + + messagingTemplate.convertAndSend("/topic/public/" + topicId, message); + } } From c611214263ab6cd29020d3c0429e3fb978ad3159 Mon Sep 17 00:00:00 2001 From: Lev Date: Sun, 15 Sep 2024 12:54:40 +0300 Subject: [PATCH 5/9] ChatController --- .../com/chat/yourway/controller/websocket/ChatController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 789186f..2ae99b0 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -16,7 +16,7 @@ public ChatController(SimpMessagingTemplate messagingTemplate) { this.messagingTemplate = messagingTemplate; } - @MessageMapping("/topic/public/{topicId}") + @MessageMapping("/app/topic/public/{topicId}") public void sendMessage(@DestinationVariable String topicId, MessageResponseDto message) { messagingTemplate.convertAndSend("/topic/public/" + topicId, message); From 7000fbd27c48f6cb8bbe45f5d3ede8d5f2851980 Mon Sep 17 00:00:00 2001 From: Lev Date: Sun, 15 Sep 2024 13:14:16 +0300 Subject: [PATCH 6/9] ChatController --- .../controller/websocket/ChatController.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 2ae99b0..d8b8f21 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -1,24 +1,36 @@ 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; - - public ChatController(SimpMessagingTemplate messagingTemplate) { - this.messagingTemplate = messagingTemplate; - } + private final MessageService messageService; @MessageMapping("/app/topic/public/{topicId}") - public void sendMessage(@DestinationVariable String topicId, MessageResponseDto message) { + public void sendMessage(@DestinationVariable UUID topicId, MessageRequestDto message) { + + log.info("Received message for topic ID: {}", topicId); + + MessageResponseDto savedMessage = 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) ; + } } From c0d6813036c9a166bc904a45fa3c3fa2da68607f Mon Sep 17 00:00:00 2001 From: Lev Date: Thu, 19 Sep 2024 22:10:13 +0300 Subject: [PATCH 7/9] ChatController fix for review --- .../com/chat/yourway/controller/websocket/ChatController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index d8b8f21..601da46 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -2,7 +2,6 @@ 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; @@ -26,11 +25,10 @@ public void sendMessage(@DestinationVariable UUID topicId, MessageRequestDto mes log.info("Received message for topic ID: {}", topicId); - MessageResponseDto savedMessage = messageService.sendToTopic(topicId, message); + 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) ; - } } From 1e31ec01674d6308daa2a3db2f6e5069eb43d285 Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 25 Sep 2024 11:46:52 +0300 Subject: [PATCH 8/9] ChatController.sendMessage fix for review --- .../com/chat/yourway/controller/websocket/ChatController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 601da46..875b112 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -2,6 +2,7 @@ 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; From ab870c81628dc858ca31a3a37b6e23db1c235f8a Mon Sep 17 00:00:00 2001 From: Lev Date: Wed, 25 Sep 2024 11:55:19 +0300 Subject: [PATCH 9/9] ChatController.sendMessage fix for review --- .../chat/yourway/controller/websocket/ChatController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java index 875b112..d62d733 100644 --- a/src/main/java/com/chat/yourway/controller/websocket/ChatController.java +++ b/src/main/java/com/chat/yourway/controller/websocket/ChatController.java @@ -22,14 +22,16 @@ public class ChatController { private final MessageService messageService; @MessageMapping("/app/topic/public/{topicId}") - public void sendMessage(@DestinationVariable UUID topicId, MessageRequestDto message) { + public MessageResponseDto sendMessage(@DestinationVariable UUID topicId, MessageRequestDto message) { log.info("Received message for topic ID: {}", topicId); - messageService.sendToTopic(topicId, message); + 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; } }