From cdbe7ecc688991fc815c68a48bccd8ad210e2024 Mon Sep 17 00:00:00 2001 From: HyemIin Date: Sat, 20 Jan 2024 01:33:28 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Feat=20:=20=EC=B5=9C=EC=8B=A0=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20DB=EC=97=90=EC=84=9C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 레디스에서 조회 - 레디스에 최신 메세지 없을 시 몽고디비에서 조회 --- .../chatroom/service/ChatRoomService.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/catchroom/chat/chatroom/service/ChatRoomService.java b/src/main/java/com/catchroom/chat/chatroom/service/ChatRoomService.java index e046336..1e2f02b 100644 --- a/src/main/java/com/catchroom/chat/chatroom/service/ChatRoomService.java +++ b/src/main/java/com/catchroom/chat/chatroom/service/ChatRoomService.java @@ -1,6 +1,7 @@ package com.catchroom.chat.chatroom.service; import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse; +import com.catchroom.chat.chatroom.entity.ChatRoom; import com.catchroom.chat.feign.client.MainFeignClient; import com.catchroom.chat.message.dto.ChatMessageDto; import com.catchroom.chat.message.entity.ChatMessage; @@ -19,14 +20,24 @@ public class ChatRoomService { public List getChatRoomList(String accessToken) { - List chatRoomListGetResponseList = mainFeignClient.getChatRoomList(accessToken); - for (ChatRoomListGetResponse chatRoomListGetResponse : chatRoomListGetResponseList) { - chatRoomListGetResponse.updateChatMessageDto(chatRoomRepository.getLastMessage(chatRoomListGetResponse.getChatRoomNumber())); -// if (chatRoomRepository.getLastMessage(chatRoomListGetResponse.getChatRoomNumber()) == null) { -// ChatMessage lastChatMessage = chatMessageRepository.findAllByRoomId(chatRoomListGetResponse.getChatRoomNumber()).get(0); -// chatRoomListGetResponse.updateChatMessageDto(ChatMessageDto.fromEntity(lastChatMessage)); -// } + List chatRoomList = mainFeignClient.getChatRoomList(accessToken); + for (ChatRoomListGetResponse chatRoomListGetResponse : chatRoomList) { + recallLastMessage(chatRoomListGetResponse); + } + return chatRoomList; + } + + private void recallLastMessage(ChatRoomListGetResponse chatRoomListGetResponse) { + String chatRoomNumber = chatRoomListGetResponse.getChatRoomNumber(); + //최신 메세지가 레디스에 있는 경우 + if (chatRoomRepository.getLastMessage(chatRoomNumber) != null) { + chatRoomListGetResponse.updateChatMessageDto(chatRoomRepository.getLastMessage(chatRoomNumber)); + } + //최신 메세지가 레디스에 없고 몽고디비에는 있는 경우 + else if (chatRoomRepository.getLastMessage(chatRoomNumber) == null && + !chatMessageRepository.findAllByRoomId(chatRoomNumber).isEmpty()) { + ChatMessage lastChatMessageMongo = chatMessageRepository.findAllByRoomId(chatRoomNumber).get(0); + chatRoomListGetResponse.updateChatMessageDto(ChatMessageDto.fromEntity(lastChatMessageMongo)); } - return chatRoomListGetResponseList; } } From cb5bd8eb69b0083c1ebdd68dfdd31156a8eddd4b Mon Sep 17 00:00:00 2001 From: HyemIin Date: Sat, 20 Jan 2024 01:36:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat=20:=20=EC=B5=9C=EC=8B=A0=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20DB=EC=97=90=EC=84=9C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 레디스에서 조회 - 레디스에 최신 메세지 없을 시 몽고디비에서 조회 --- .../catchroom/chat/chatroom/controller/ChatRoomController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java b/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java index 3c30f54..df93ac8 100644 --- a/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java +++ b/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java @@ -19,7 +19,6 @@ public class ChatRoomController { public List getChatRoomList( @RequestHeader("Authorization") String accessToken ) { - log.error("accesstoken = " + accessToken); return chatRoomService.getChatRoomList(accessToken); } From 51c8c6963c8fb181c1f652c4f6b25b78e45d68c9 Mon Sep 17 00:00:00 2001 From: HyemIin Date: Sat, 20 Jan 2024 01:36:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Feat=20:=20=EC=B5=9C=EC=8B=A0=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20DB=EC=97=90=EC=84=9C=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 레디스에서 조회 - 레디스에 최신 메세지 없을 시 몽고디비에서 조회 --- .../catchroom/chat/chatroom/controller/ChatRoomController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java b/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java index df93ac8..1ceead1 100644 --- a/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java +++ b/src/main/java/com/catchroom/chat/chatroom/controller/ChatRoomController.java @@ -11,7 +11,6 @@ @RequestMapping("/v1/chat/room") @RequiredArgsConstructor @CrossOrigin(origins = "https://localhost:3000", allowedHeaders = "*") -@Slf4j public class ChatRoomController { private final ChatRoomService chatRoomService;