-
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.
- Loading branch information
Showing
8 changed files
with
72 additions
and
31 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
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
2 changes: 1 addition & 1 deletion
2
...s/rest/resources/ChatMessageResource.java → ...shared/resources/ChatMessageResource.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
4 changes: 2 additions & 2 deletions
4
...atMessageResourceFromEntityAssembler.java → ...atMessageResourceFromEntityAssembler.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
31 changes: 31 additions & 0 deletions
31
chat-server/src/main/java/me/ryzeon/chatserver/chat/interfaces/socket/ChatMessageSocket.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,31 @@ | ||
package me.ryzeon.chatserver.chat.interfaces.socket; | ||
|
||
import lombok.AllArgsConstructor; | ||
import me.ryzeon.chatserver.chat.domain.services.ChatMessageCommandService; | ||
import me.ryzeon.chatserver.chat.domain.services.ChatMessageQueryService; | ||
import me.ryzeon.chatserver.chat.interfaces.socket.resources.CreateChatMessageResource; | ||
import me.ryzeon.chatserver.chat.interfaces.shared.transform.ChatMessageResourceFromEntityAssembler; | ||
import me.ryzeon.chatserver.chat.interfaces.socket.transform.CreateChatMessageCommandFromResourceAssembler; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/chat-messages") | ||
@AllArgsConstructor | ||
public class ChatMessageSocket { | ||
|
||
private final ChatMessageCommandService chatMessagesCommandService; | ||
private final ChatMessageQueryService chatMessagesQueryService; | ||
private final SimpMessagingTemplate simpMessagingTemplate; | ||
|
||
@MessageMapping | ||
public void createChatMessage(@Payload CreateChatMessageResource resource) { | ||
var createChatMessageCommand = CreateChatMessageCommandFromResourceAssembler.toCommandFromResource(resource); | ||
var chatMessage = chatMessagesCommandService.handle(createChatMessageCommand).orElseThrow(() -> new RuntimeException("Chat message not created")); | ||
var chatMessageResource = ChatMessageResourceFromEntityAssembler.toResourceFromEntity(chatMessage); | ||
simpMessagingTemplate.convertAndSend("/topic/chat-group." + chatMessage.getGroupId(), chatMessageResource); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
chat-server/src/main/java/me/ryzeon/chatserver/chat/interfaces/socket/UserSocket.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,33 @@ | ||
package me.ryzeon.chatserver.chat.interfaces.socket; | ||
|
||
import lombok.AllArgsConstructor; | ||
import me.ryzeon.chatserver.chat.domain.model.commands.JoinUserGroupCommand; | ||
import me.ryzeon.chatserver.chat.domain.model.commands.LeaveUserGroupCommand; | ||
import me.ryzeon.chatserver.chat.domain.services.UserCommandService; | ||
import me.ryzeon.chatserver.chat.domain.services.UserQueryService; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.SendTo; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@AllArgsConstructor | ||
public class UserSocket { | ||
|
||
private final UserCommandService userCommandService; | ||
private final UserQueryService userQueryService; | ||
|
||
@MessageMapping("/user.leaveFromGroup") | ||
@SendTo("/user/topic") | ||
|
||
public void leaveUserFromGroup(Long userId, Long chatGroupId) { | ||
var leaveUserGroupCommand = new LeaveUserGroupCommand(userId, chatGroupId); | ||
userCommandService.handle(leaveUserGroupCommand); | ||
} | ||
|
||
@MessageMapping("/user.joinToGroup") | ||
@SendTo("/user/topic") | ||
public void joinUserToGroup(Long userId, Long chatGroupId) { | ||
var joinUserGroupCommand = new JoinUserGroupCommand(userId, chatGroupId); | ||
userCommandService.handle(joinUserGroupCommand); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../resources/CreateChatMessageResource.java → .../resources/CreateChatMessageResource.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
4 changes: 2 additions & 2 deletions
4
...tMessageCommandFromResourceAssembler.java → ...tMessageCommandFromResourceAssembler.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