-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Send Chat Message Usecase (#186)
* rename: transfer command to command package * chore: add jackson validation dependency in to the socket module * chore: add spring-validation dependency in to the socket module * rename: package path modification * fix: add type field in the rabbit_listener exchange property's type field * fix: delete constants in the listener * feat: chat_message_dto * feat: chat_message_controller * feat: add dto validation * fix: chat_message entity's @redis_hash is chatroom * fix: dto wrap final class * fix: when message send to rabbitmq, using response dto * rename: delete send_message_commend unused annotation * fix: get_chat_room_id and get_chat_id method in the chat_message fix index * refactor: when chat message send to rabbitmq, it's will be dto type * test: dao test expected redis key fix
- Loading branch information
1 parent
444ad64
commit 19be782
Showing
8 changed files
with
97 additions
and
19 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
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
26 changes: 26 additions & 0 deletions
26
pennyway-socket/src/main/java/kr/co/pennyway/socket/controller/ChatMessageController.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,26 @@ | ||
package kr.co.pennyway.socket.controller; | ||
|
||
import kr.co.pennyway.socket.command.SendMessageCommand; | ||
import kr.co.pennyway.socket.common.annotation.PreAuthorize; | ||
import kr.co.pennyway.socket.common.security.authenticate.UserPrincipal; | ||
import kr.co.pennyway.socket.dto.ChatMessageDto; | ||
import kr.co.pennyway.socket.service.ChatMessageSendService; | ||
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.stereotype.Controller; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Slf4j | ||
@Controller | ||
@RequiredArgsConstructor | ||
public class ChatMessageController { | ||
private final ChatMessageSendService chatMessageSendService; | ||
|
||
@MessageMapping("chat.message.{chatRoomId}") | ||
@PreAuthorize("#isAuthenticated(#principal) and @chatRoomAccessChecker.hasPermission(#chatRoomId, #principal)") | ||
public void sendMessage(@DestinationVariable Long chatRoomId, @Validated ChatMessageDto.Request payload, UserPrincipal principal) { | ||
chatMessageSendService.execute(SendMessageCommand.createUserMessage(chatRoomId, payload.content(), payload.contentType(), principal.getUserId())); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
pennyway-socket/src/main/java/kr/co/pennyway/socket/dto/ChatMessageDto.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,47 @@ | ||
package kr.co.pennyway.socket.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import kr.co.pennyway.domain.common.redis.message.domain.ChatMessage; | ||
import kr.co.pennyway.domain.common.redis.message.type.MessageCategoryType; | ||
import kr.co.pennyway.domain.common.redis.message.type.MessageContentType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public final class ChatMessageDto { | ||
public record Request( | ||
@NotNull(message = "메시지 내용은 null을 허용하지 않습니다.") | ||
@Size(min = 1, max = 1000, message = "메시지 내용은 1자 이상 1000자 이하로 입력해주세요.") | ||
String content, | ||
@NotNull(message = "메시지 타입은 null을 허용하지 않습니다.") | ||
MessageContentType contentType | ||
) { | ||
} | ||
|
||
public record Response( | ||
Long chatRoomId, | ||
Long chatId, | ||
String content, | ||
MessageContentType contentType, | ||
MessageCategoryType categoryType, | ||
@JsonSerialize(using = LocalDateTimeSerializer.class) | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
LocalDateTime createdAt, | ||
Long senderId | ||
) { | ||
public static Response from(ChatMessage message) { | ||
return new Response( | ||
message.getChatRoomId(), | ||
message.getChatId(), | ||
message.getContent(), | ||
message.getContentType(), | ||
message.getCategoryType(), | ||
message.getCreatedAt(), | ||
message.getSender() | ||
); | ||
} | ||
} | ||
} |
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