Skip to content

Commit

Permalink
Merge pull request #33 from catchroom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
HyemIin authored Jan 19, 2024
2 parents d986af6 + 51c8c69 commit ba3bb92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
@RequestMapping("/v1/chat/room")
@RequiredArgsConstructor
@CrossOrigin(origins = "https://localhost:3000", allowedHeaders = "*")
@Slf4j
public class ChatRoomController {
private final ChatRoomService chatRoomService;

@GetMapping("/list")
public List<ChatRoomListGetResponse> getChatRoomList(
@RequestHeader("Authorization") String accessToken
) {
log.error("accesstoken = " + accessToken);
return chatRoomService.getChatRoomList(accessToken);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,14 +20,24 @@ public class ChatRoomService {


public List<ChatRoomListGetResponse> getChatRoomList(String accessToken) {
List<ChatRoomListGetResponse> 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<ChatRoomListGetResponse> 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;
}
}

0 comments on commit ba3bb92

Please sign in to comment.