Skip to content

Commit

Permalink
fix: inactive 변경 후 저장 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunn522 committed Aug 18, 2024
1 parent dc0d1e1 commit 3dccda5
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/main/java/space/space_spring/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public ReadChatRoomResponse readChatRooms(Long userId, Long spaceId) {
Space spaceBySpaceId = spaceUtils.findSpaceBySpaceId(spaceId);

// TODO 3: 해당 user의 해당 space 내의 채팅방 리스트 return
List<ChatRoom> result = chatRoomDao.findByUserAndSpace(userByUserId, spaceBySpaceId);
List<ChatRoom> chatRoomList = chatRoomDao.findByUserAndSpace(userByUserId, spaceBySpaceId);

return ReadChatRoomResponse.of(result.stream()
// TODO 4: chatRoom 리스트에서 active만 find
List<ChatRoom> activeChatRooms = chatRoomList.stream()
.filter(userChatRoom -> "ACTIVE".equals(userChatRoom.getStatus()))
.toList();

return ReadChatRoomResponse.of(activeChatRooms.stream()
.map(cr -> {
// TODO 4: 각 채팅방의 마지막으로 업데이트된 메시지 정보 find
// TODO 5: 각 채팅방의 마지막으로 업데이트된 메시지 정보 find
ChatMessage lastMsg = chattingDao.findTopByChatRoomIdOrderByCreatedAtDesc(cr.getId());

LocalDateTime lastUpdateTime = cr.getCreatedAt().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
Expand All @@ -65,7 +70,7 @@ public ReadChatRoomResponse readChatRooms(Long userId, Long spaceId) {
lastContent = lastMsg.getContent();
}

// TODO 5: 각 채팅방의 안읽은 메시지 개수 계산
// TODO 6: 각 채팅방의 안읽은 메시지 개수 계산
UserChatRoom userChatRoom = userChatRoomDao.findByUserAndChatRoom(userByUserId, cr);
LocalDateTime lastReadTime = userChatRoom.getLastReadTime().atZone(ZoneId.of("Asia/Seoul")).toLocalDateTime();
int unreadMsgCount = chattingDao.countByChatRoomIdAndCreatedAtBetween(
Expand Down Expand Up @@ -112,10 +117,15 @@ public ReadChatRoomMemberResponse readChatRoomMembers(Long spaceId, Long chatRoo
// TODO 3: 해당 chatRoom의 userChatRoom 리스트 find
List<UserChatRoom> userChatRoomList = userChatRoomDao.findByChatRoom(chatRoomById);

userChatRoomList.forEach(userChatRoom -> {
// TODO 4: userChatRoom 리스트에서 active만 find
List<UserChatRoom> activeUserChatRooms = userChatRoomList.stream()
.filter(userChatRoom -> "ACTIVE".equals(userChatRoom.getStatus()))
.toList();

activeUserChatRooms.forEach(userChatRoom -> {
User user = userChatRoom.getUser();

// TODO 4: 스페이스 프로필 이미지 get 위해 userSpace find
// TODO 5: 스페이스 프로필 이미지 get 위해 userSpace find
UserSpace userSpace = userSpaceDao.findUserSpaceByUserAndSpace(user, spaceById)
.orElseThrow(() -> new CustomException(USER_IS_NOT_IN_SPACE));

Expand Down Expand Up @@ -170,6 +180,9 @@ public ChatSuccessResponse exitChatRoom(Long userId, Long chatRoomId) {
// TODO 2: 해당 userChatRoom inactive로 변경
userChatRoom.updateInactive();

// TODO 3: DB에 변경 사항 저장
userChatRoomDao.save(userChatRoom);

return ChatSuccessResponse.of(true);
}

Expand All @@ -178,8 +191,12 @@ public ChatSuccessResponse deleteChatRoom(Long chatRoomId) {
ChatRoom chatRoomByChatRoomId = chatRoomDao.findById(chatRoomId)
.orElseThrow(() -> new CustomException(CHATROOM_NOT_EXIST));

// TODO 2: 해당 chatRoom inactive로 변경
chatRoomByChatRoomId.updateInactive();

// TODO 3: DB에 변경 사항 저장
chatRoomDao.save(chatRoomByChatRoomId);

return ChatSuccessResponse.of(true);
}

Expand Down

0 comments on commit 3dccda5

Please sign in to comment.