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

[SIX-264] 채팅방 조회 로직 리팩토링 #115

Merged
merged 3 commits into from
Nov 27, 2023
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
130 changes: 65 additions & 65 deletions onedayhero-api/src/main/resources/static/docs/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.sixheroes.onedayheroapplication.chatroom;

import com.sixheroes.onedayheroapplication.chatroom.repository.UserMissionChatRoomQueryRepository;
import com.sixheroes.onedayheroapplication.chatroom.repository.response.UserMissionChatRoomQueryResponse;
import com.sixheroes.onedayheroapplication.chatroom.request.CreateMissionChatRoomServiceRequest;
import com.sixheroes.onedayheroapplication.chatroom.response.MissionChatRoomCreateResponse;
import com.sixheroes.onedayheroapplication.chatroom.response.MissionChatRoomExitResponse;
Expand Down Expand Up @@ -35,7 +33,6 @@ public class ChatRoomService {
private final MissionChatRoomReader missionChatRoomReader;
private final MissionChatRoomRepository missionChatRoomRepository;
private final UserMissionChatRoomRepository userMissionChatRoomRepository;
private final UserMissionChatRoomQueryRepository userMissionChatRoomQueryRepository;
private final UserMissionChatRoomReader userMissionChatRoomReader;
private final MissionChatRoomRedisRepository missionChatRoomRedisRepository;
private final ChatMessageMongoRepository chatMessageMongoRepository;
Expand All @@ -54,7 +51,8 @@ public MissionChatRoomCreateResponse createChatRoom(
public List<MissionChatRoomFindResponse> findJoinedChatRoom(
Long userId
) {
var missionChatRooms = userMissionChatRoomQueryRepository.findJoinedChatRooms(userId);
var missionChatRooms = userMissionChatRoomRepository.findByUserIdAndIsJoinedTrue(userId);

var chatRoomIds = getJoinedChatRoomIds(missionChatRooms);
var receiverIds = getReceiverIds(userId, chatRoomIds);

Expand Down Expand Up @@ -88,14 +86,21 @@ public MissionChatRoomExitResponse exitChatRoom(
return MissionChatRoomExitResponse.from(userChatRoom.getMissionChatRoom(), userId);
}

private List<Long> getJoinedChatRoomIds(List<UserMissionChatRoomQueryResponse> missionChatRooms) {
return missionChatRooms.stream()
.mapToLong(UserMissionChatRoomQueryResponse::chatRoomId)
// 유저가 나가지 않은 채팅방에 속한 다른 유저들을 조회한다.
private List<Long> getJoinedChatRoomIds(
List<UserMissionChatRoom> userMissionChatRooms
) {
return userMissionChatRooms.stream()
.mapToLong((userMissionChatRoom) -> userMissionChatRoom.getMissionChatRoom().getId())
.boxed()
.toList();
}

private List<Long> getReceiverIds(Long userId, List<Long> chatRoomIds) {
// 채팅 수신자에 대한 수신자 아이디를 가지고 온다.
private List<Long> getReceiverIds(
Long userId,
List<Long> chatRoomIds
) {
return userMissionChatRoomRepository.findByMissionChatRoom_IdIn(chatRoomIds)
.stream()
.filter(userMissionChatRoom -> !userMissionChatRoom.isUserChatRoom(userId))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소하지만 Predicate의 not을 쓰면 더 직관적일 것 같습니다..!!

Expand All @@ -104,6 +109,7 @@ private List<Long> getReceiverIds(Long userId, List<Long> chatRoomIds) {
.toList();
}

// 똑같은 채팅방 ID에 속한 값으로 채팅방 목록 응답 값을 생성한다.
private List<MissionChatRoomFindResponse> makeMissionChatRoomResponse(
List<UserChatRoomQueryResponse> receiverChatRoomInfos,
List<ChatMessage> latestMessagesByChatRoomIds
Expand All @@ -127,14 +133,6 @@ private List<MissionChatRoomFindResponse> makeMissionChatRoomResponse(
return result;
}

public MissionChatRoomCreateResponse findOne(
Long missionChatRoomId
) {
var missionChatRoom = missionChatRoomReader.findById(missionChatRoomId);

return MissionChatRoomCreateResponse.from(missionChatRoom);
}

private UserMissionChatRoom getUserChatRoom(
Long userId,
List<UserMissionChatRoom> findMissionChatRooms
Expand All @@ -147,4 +145,12 @@ private UserMissionChatRoom getUserChatRoom(
return new IllegalArgumentException(ErrorCode.T_001.name());
});
}

public MissionChatRoomCreateResponse findOne(
Long missionChatRoomId
) {
var missionChatRoom = missionChatRoomReader.findById(missionChatRoomId);

return MissionChatRoomCreateResponse.from(missionChatRoom);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.sixheroes.onedayherodomain.mission.repository.MissionCategoryRepository;
import com.sixheroes.onedayherodomain.mission.repository.MissionImageRepository;
import com.sixheroes.onedayherodomain.mission.repository.MissionRepository;
import com.sixheroes.onedayherodomain.missionchatroom.repository.MissionChatRoomRepository;
import com.sixheroes.onedayherodomain.missionchatroom.repository.UserMissionChatRoomRepository;
import com.sixheroes.onedayherodomain.missionproposal.repository.MissionProposalRepository;
import com.sixheroes.onedayherodomain.region.Region;
import com.sixheroes.onedayherodomain.region.repository.RegionRepository;
Expand All @@ -27,6 +29,7 @@
import com.sixheroes.onedayherodomain.user.repository.UserMissionCategoryRepository;
import com.sixheroes.onedayherodomain.user.repository.UserRegionRepository;
import com.sixheroes.onedayherodomain.user.repository.UserRepository;
import com.sixheroes.onedayheromongo.chat.repository.ChatMessageMongoRepository;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -55,6 +58,12 @@ public abstract class IntegrationApplicationTest {
@Autowired
protected RegionRepository regionRepository;

@Autowired
protected MissionChatRoomRepository missionChatRoomRepository;

@Autowired
protected UserMissionChatRoomRepository userMissionChatRoomRepository;

@Autowired
protected MissionService missionService;

Expand Down Expand Up @@ -112,6 +121,9 @@ public abstract class IntegrationApplicationTest {
@MockBean
protected MissionChatRoomRedisRepository missionChatRoomRedisRepository;

@MockBean
protected ChatMessageMongoRepository chatMessageMongoRepository;

@BeforeAll
public static void setUp(
@Autowired MissionCategoryRepository missionCategoryRepository,
Expand Down
Loading