Skip to content

Commit

Permalink
Merge pull request #114 from KUIT-Space/hotfix/last-message-time-버그-수정
Browse files Browse the repository at this point in the history
Hotfix: lastMsg 예외처리 및 타입 변경
  • Loading branch information
hyunn522 authored Aug 16, 2024
2 parents e90b5f0 + b98511d commit 9080b49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Getter;
import space.space_spring.entity.ChatRoom;

import java.util.HashMap;

@Builder
@Getter
@AllArgsConstructor
Expand All @@ -15,13 +17,13 @@ public class ChatRoomResponse {

private String imgUrl;

private String lastMsg;
private HashMap<String, String> lastMsg;

private String lastTime;

private int unreadMsgCount;

public static ChatRoomResponse of(ChatRoom chatRoom, String lastMsg, String lastTime, int unreadMsgCount) {
public static ChatRoomResponse of(ChatRoom chatRoom, HashMap<String, String> lastMsg, String lastTime, int unreadMsgCount) {
return ChatRoomResponse.builder()
.id(chatRoom.getId())
.name(chatRoom.getName())
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/space/space_spring/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -53,18 +54,15 @@ public ReadChatRoomResponse readChatRooms(Long userId, Long spaceId) {
.map(cr -> {
// TODO 4: 각 채팅방의 마지막으로 업데이트된 메시지 정보 find
ChatMessage lastMsg = chattingDao.findTopByChatRoomIdOrderByCreatedAtDesc(cr.getId());
LocalDateTime lastUpdateTime = lastMsg.getCreatedAt();
String lastContent = switch (lastMsg.getMessageType()) {
case TEXT -> lastMsg.getContent().get("text");
/**
* TODO: 메시지 타입 관련하여 미리보기 뷰에 따라 변경 가능
*/
// case IMG -> "img";
// case FILE -> "file";
// case POST -> "post";
// case PAY -> "pay";
default -> lastMsg.getMessageType().toString();
};

LocalDateTime lastUpdateTime = LocalDateTime.now();
HashMap<String, String> lastContent = new HashMap<>();
lastContent.put("text", "메시지를 전송해보세요");

if (lastMsg != null) {
lastUpdateTime = lastMsg.getCreatedAt();
lastContent = lastMsg.getContent();
}

// TODO 5: 각 채팅방의 안읽은 메시지 개수 계산
UserChatRoom userChatRoom = userChatRoomDao.findByUserAndChatRoom(userByUserId, cr);
Expand Down

0 comments on commit 9080b49

Please sign in to comment.