diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/chat/ChatFacade.java b/tht-apis/src/main/java/com/tht/thtapis/facade/chat/ChatFacade.java index 6e9de1ef..2067a055 100644 --- a/tht-apis/src/main/java/com/tht/thtapis/facade/chat/ChatFacade.java +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/chat/ChatFacade.java @@ -1,6 +1,8 @@ package com.tht.thtapis.facade.chat; import com.tht.domain.entity.chat.group.ChatRoomMapperGroup; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; +import com.tht.domain.entity.user.User; import com.tht.thtapis.facade.Facade; import com.tht.thtapis.facade.chat.group.ChatHistoryGroup; import com.tht.thtapis.facade.chat.group.ChatRoomPreviewMapperGroup; @@ -58,8 +60,9 @@ public ChatRoomResponse findMyRoomDetail(final long chatRoomIdx, final String us chatRoomService.existBy(chatRoomIdx); - ChatRoomMapperGroup group = chatRoomService.findDetailInfoById(chatRoomIdx, userUuid); + final ChatRoomMapperGroup group = chatRoomService.findDetailInfoById(chatRoomIdx, userUuid); + final List allParticipator = chatRoomUserService.findAllParticipator(chatRoomIdx); - return ChatRoomResponse.of(group.getBasic(), group.isChatAble()); + return ChatRoomResponse.of(group.getBasic(), group.isChatAble(), allParticipator); } } diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/chat/response/ChatRoomResponse.java b/tht-apis/src/main/java/com/tht/thtapis/facade/chat/response/ChatRoomResponse.java index 63e61202..e34da6a8 100644 --- a/tht-apis/src/main/java/com/tht/thtapis/facade/chat/response/ChatRoomResponse.java +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/chat/response/ChatRoomResponse.java @@ -1,24 +1,40 @@ package com.tht.thtapis.facade.chat.response; import com.tht.domain.entity.chat.mapper.ChatRoomMapper; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; +import com.tht.domain.entity.user.User; import java.time.format.DateTimeFormatter; +import java.util.List; public record ChatRoomResponse( long chatRoomIdx, String talkSubject, String talkIssue, String startDate, - boolean isChatAble + boolean isChatAble, + List participants ) { - public static ChatRoomResponse of(final ChatRoomMapper mapper, final boolean isChatAble) { + public static ChatRoomResponse of(final ChatRoomMapper mapper, final boolean isChatAble, List allParticipator) { return new ChatRoomResponse( mapper.chatRoomIdx(), mapper.talkSubject(), mapper.talkIssue(), mapper.startDate().format(DateTimeFormatter.ofPattern("y년 M월 d일")), - isChatAble + isChatAble, + allParticipator.stream().map(Participant::of).toList() ); } } + +record Participant( + String userUuid, + String userName, + String profileUrl +) { + + public static Participant of(final ChatRoomUserMapper user) { + return new Participant(user.userUuid(), user.userName(), user.profileUrl()); + } +} diff --git a/tht-apis/src/test/java/com/tht/thtapis/documentation/ChatDocumentation.java b/tht-apis/src/test/java/com/tht/thtapis/documentation/ChatDocumentation.java index a50e9488..e6f1cbc5 100644 --- a/tht-apis/src/test/java/com/tht/thtapis/documentation/ChatDocumentation.java +++ b/tht-apis/src/test/java/com/tht/thtapis/documentation/ChatDocumentation.java @@ -183,7 +183,11 @@ void getDetailRoomInfo() throws Exception { fieldWithPath("talkSubject").description("대화 주제"), fieldWithPath("talkIssue").description("대화 주제 파생질문"), fieldWithPath("startDate").description("재화 시작일"), - fieldWithPath("isChatAble").description("채팅 가능여부") + fieldWithPath("isChatAble").description("채팅 가능여부"), + fieldWithPath("participants").description("채팅방 참가자 리스트"), + fieldWithPath("participants[].userUuid").description("참가자 고유 번호"), + fieldWithPath("participants[].userName").description("참가자 이름"), + fieldWithPath("participants[].profileUrl").description("참가자 프로필 대표사진 url") ) .build() ) diff --git a/tht-apis/src/test/java/com/tht/thtapis/facade/chat/ChatFacadeTest.java b/tht-apis/src/test/java/com/tht/thtapis/facade/chat/ChatFacadeTest.java index 0a1b9a06..807ce32d 100644 --- a/tht-apis/src/test/java/com/tht/thtapis/facade/chat/ChatFacadeTest.java +++ b/tht-apis/src/test/java/com/tht/thtapis/facade/chat/ChatFacadeTest.java @@ -1,6 +1,7 @@ package com.tht.thtapis.facade.chat; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.BDDMockito.anyInt; import static org.mockito.BDDMockito.anyLong; diff --git a/tht-apis/src/test/java/com/tht/thtapis/fixture/chat/ChatRoomResponseFixture.java b/tht-apis/src/test/java/com/tht/thtapis/fixture/chat/ChatRoomResponseFixture.java index 0456b50a..d7aceab3 100644 --- a/tht-apis/src/test/java/com/tht/thtapis/fixture/chat/ChatRoomResponseFixture.java +++ b/tht-apis/src/test/java/com/tht/thtapis/fixture/chat/ChatRoomResponseFixture.java @@ -1,5 +1,8 @@ package com.tht.thtapis.fixture.chat; +import com.tht.domain.entity.chat.mapper.ChatRoomMapper; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; +import com.tht.enums.EntityState; import com.tht.thtapis.facade.chat.response.ChatRoomPreviewResponse; import com.tht.thtapis.facade.chat.response.ChatRoomResponse; @@ -29,6 +32,13 @@ public static List makePreviewResponseList() { } public static ChatRoomResponse make() { - return new ChatRoomResponse(chatRoomIdx,talkSubject, talkIssue, startDate, isChatAble); + List users = List.of( + new ChatRoomUserMapper("1번-user-uuid", "1번 참가자 이름", "1번 참가자 대표 사진"), + new ChatRoomUserMapper("2번-user-uuid", "2번 참가자 이름", "2번 참가자 대표 사진") + ); + + ChatRoomMapper chatRoomMapper = new ChatRoomMapper(chatRoomIdx, talkSubject, talkIssue, LocalDateTime.now(), EntityState.ACTIVE, EntityState.ACTIVE); + + return ChatRoomResponse.of(chatRoomMapper, isChatAble, users); } } diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/mapper/ChatRoomUserMapper.java b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/mapper/ChatRoomUserMapper.java new file mode 100644 index 00000000..7bb2c131 --- /dev/null +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/mapper/ChatRoomUserMapper.java @@ -0,0 +1,13 @@ +package com.tht.domain.entity.chat.mapper; + +import com.querydsl.core.annotations.QueryProjection; + +public record ChatRoomUserMapper( + String userUuid, + String userName, + String profileUrl +) { + + @QueryProjection + public ChatRoomUserMapper {} +} diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/ChatRoomUserCustomRepository.java b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/ChatRoomUserCustomRepository.java index eaa4494a..26d1fb98 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/ChatRoomUserCustomRepository.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/ChatRoomUserCustomRepository.java @@ -2,6 +2,8 @@ import com.tht.domain.entity.chat.mapper.ChatRoomPreviewMapper; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; +import com.tht.domain.entity.user.User; import java.util.List; @@ -12,4 +14,6 @@ public interface ChatRoomUserCustomRepository { void updateChatRoomUserInActive(final long chatRoomIdx, final String userUuid); void updateChatRoomUserInActiveOfBlock(final String userUuid, final String blockUserUuid); + + List findAllActiveParticipator(final long chatRoomIdx); } diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/querydsl/ChatRoomUserCustomRepositoryImpl.java b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/querydsl/ChatRoomUserCustomRepositoryImpl.java index 1cf89ed1..fba59e7d 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/querydsl/ChatRoomUserCustomRepositoryImpl.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/repository/querydsl/ChatRoomUserCustomRepositoryImpl.java @@ -1,6 +1,9 @@ package com.tht.domain.entity.chat.repository.querydsl; import com.querydsl.jpa.impl.JPAQueryFactory; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; +import com.tht.domain.entity.chat.mapper.QChatRoomUserMapper; +import com.tht.domain.entity.user.User; import com.tht.enums.EntityState; import com.tht.domain.entity.chat.QChatRoom; import com.tht.domain.entity.chat.QChatRoomUser; @@ -70,7 +73,7 @@ public void updateChatRoomUserInActive(final long chatRoomIdx, final String user @Override public void updateChatRoomUserInActiveOfBlock(final String userUuid, - final String blockUserUuid) { + final String blockUserUuid) { final List blockUserChatRoomIdxList = queryFactory.select(chatRoomUser.chatRoomIdx) .from(chatRoomUser) @@ -88,4 +91,25 @@ public void updateChatRoomUserInActiveOfBlock(final String userUuid, .execute(); } + @Override + public List findAllActiveParticipator(long chatRoomIdx) { + + int representativePhoto = 1; + return queryFactory.select( + new QChatRoomUserMapper( + user.userUuid, + user.username, + userProfilePhoto.url + ) + ) + .from(chatRoomUser) + .innerJoin(user).on(chatRoomUser.userUuid.eq(user.userUuid)) + .innerJoin(userProfilePhoto).on(user.userUuid.eq(userProfilePhoto.userUuid).and(userProfilePhoto.priority.eq(representativePhoto))) + .where( + chatRoomUser.chatRoomIdx.eq(chatRoomIdx), + chatRoomUser.state.eq(EntityState.ACTIVE) + ) + .fetch(); + } + } diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/service/ChatRoomUserService.java b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/service/ChatRoomUserService.java index be99e572..536d712c 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/chat/service/ChatRoomUserService.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/chat/service/ChatRoomUserService.java @@ -4,7 +4,9 @@ import com.tht.domain.entity.chat.ChatRoomUser; import com.tht.domain.entity.chat.mapper.ChatRoomPreviewMapper; +import com.tht.domain.entity.chat.mapper.ChatRoomUserMapper; import com.tht.domain.entity.chat.repository.ChatRoomUserRepository; +import com.tht.domain.entity.user.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,4 +33,8 @@ public void inChatRoom(final long chatRoomIdx, final String userUuid) { public void outOfBlockChatRoom(final String userUuid, final String blockUserUuid) { chatRoomUserRepository.updateChatRoomUserInActiveOfBlock(userUuid, blockUserUuid); } + + public List findAllParticipator(final long chatRoomIdx) { + return chatRoomUserRepository.findAllActiveParticipator(chatRoomIdx); + } }