Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: lastMsg 예외처리 및 타입 변경 #114

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading