From b5b784909be6a8161f20cc2b32a582010d9ec05e Mon Sep 17 00:00:00 2001 From: haen-su Date: Wed, 15 Nov 2023 07:12:22 +0900 Subject: [PATCH] refactor: edit message dtos(senderId -> senderUsername) --- .../server/api/chat/dto/request/MessageRequest.java | 2 +- .../api/chat/dto/response/MessageListResponse.java | 6 +++--- .../api/chat/dto/response/MessageResponse.java | 12 ++++++++---- .../api/chat/service/EnterChatroomService.java | 2 +- .../oven/server/api/chat/service/MessageService.java | 5 +++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/oven/server/api/chat/dto/request/MessageRequest.java b/src/main/java/com/oven/server/api/chat/dto/request/MessageRequest.java index 0abad40..6140d7e 100644 --- a/src/main/java/com/oven/server/api/chat/dto/request/MessageRequest.java +++ b/src/main/java/com/oven/server/api/chat/dto/request/MessageRequest.java @@ -10,6 +10,6 @@ public class MessageRequest { private String content; @Schema(description = "메시지 발신인 ID", example = "id2023") - private String senderId; + private String senderUsername; } \ No newline at end of file diff --git a/src/main/java/com/oven/server/api/chat/dto/response/MessageListResponse.java b/src/main/java/com/oven/server/api/chat/dto/response/MessageListResponse.java index abfeb03..b41caf8 100644 --- a/src/main/java/com/oven/server/api/chat/dto/response/MessageListResponse.java +++ b/src/main/java/com/oven/server/api/chat/dto/response/MessageListResponse.java @@ -21,14 +21,14 @@ public class MessageListResponse { private boolean isSender; @Schema(description = "메시지 발신 유저 닉네임", example = "오븐조아") - private String sender; + private String senderNickname; @Builder - public MessageListResponse(String content, LocalDateTime sendTime, boolean isSender, String sender) { + public MessageListResponse(String content, LocalDateTime sendTime, boolean isSender, String senderNickname) { this.content = content; this.sendTime = sendTime; this.isSender = isSender; - this.sender = sender; + this.senderNickname = senderNickname; } } diff --git a/src/main/java/com/oven/server/api/chat/dto/response/MessageResponse.java b/src/main/java/com/oven/server/api/chat/dto/response/MessageResponse.java index 44f5b97..a800c88 100644 --- a/src/main/java/com/oven/server/api/chat/dto/response/MessageResponse.java +++ b/src/main/java/com/oven/server/api/chat/dto/response/MessageResponse.java @@ -14,17 +14,21 @@ public class MessageResponse { private String content; @Schema(description = "메시지 전송 시간") - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "hh:MM", timezone = "Asia/Seoul") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "hh:mm", timezone = "Asia/Seoul") private LocalDateTime sendTime; + @Schema(description = "메시지 발신인 아이디", example = "id2023") + private String senderUsername; + @Schema(description = "메시지 발신인 닉네임", example = "오븐조아") - private String sender; + private String senderNickname; @Builder - public MessageResponse(String content, LocalDateTime sendTime, String sender) { + public MessageResponse(String content, LocalDateTime sendTime, String senderUsername, String senderNickname) { this.content = content; this.sendTime = sendTime; - this.sender = sender; + this.senderUsername = senderUsername; + this.senderNickname = senderNickname; } } diff --git a/src/main/java/com/oven/server/api/chat/service/EnterChatroomService.java b/src/main/java/com/oven/server/api/chat/service/EnterChatroomService.java index 196d75f..7bb263c 100644 --- a/src/main/java/com/oven/server/api/chat/service/EnterChatroomService.java +++ b/src/main/java/com/oven/server/api/chat/service/EnterChatroomService.java @@ -44,7 +44,7 @@ public EnterChatroomResponse enterChatroom(User user, Long chatroomId) { .content(message.getContent()) .isSender(message.getSender().getId().equals(user.getId())) .sendTime(message.getCreatedAt()) - .sender(message.getSender().getNickname()) + .senderNickname(message.getSender().getNickname()) .build() ) .collect(Collectors.toList()) diff --git a/src/main/java/com/oven/server/api/chat/service/MessageService.java b/src/main/java/com/oven/server/api/chat/service/MessageService.java index 9085d4c..5f93753 100644 --- a/src/main/java/com/oven/server/api/chat/service/MessageService.java +++ b/src/main/java/com/oven/server/api/chat/service/MessageService.java @@ -34,7 +34,7 @@ public void sendMessage(Long chatroomId, MessageRequest messageRequest) { () -> new BaseException(ResponseCode.CHATROOM_NOT_FOUND) ); - User user = userRepository.findByUsername(messageRequest.getSenderId()).orElseThrow( + User user = userRepository.findByUsername(messageRequest.getSenderUsername()).orElseThrow( () -> new BaseException(ResponseCode.USER_NOT_FOUND) ); @@ -49,7 +49,8 @@ public void sendMessage(Long chatroomId, MessageRequest messageRequest) { MessageResponse messageResponse = MessageResponse.builder() .content(message.getContent()) .sendTime(message.getCreatedAt()) - .sender(user.getNickname()) + .senderUsername(user.getUsername()) + .senderNickname(user.getNickname()) .build(); template.convertAndSend("/sub/chatrooms/" + chatroomId + "/message", messageResponse);