Skip to content

Commit

Permalink
THT-Server-270 [App] 채팅방 데이터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
thalals committed Jan 18, 2025
1 parent 09cf7b8 commit 009f4fd
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ChatRoomUserMapper> allParticipator = chatRoomUserService.findAllParticipator(chatRoomIdx);

return ChatRoomResponse.of(group.getBasic(), group.isChatAble());
return ChatRoomResponse.of(group.getBasic(), group.isChatAble(), allParticipator);
}
}
Original file line number Diff line number Diff line change
@@ -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<Participant> participants
) {

public static ChatRoomResponse of(final ChatRoomMapper mapper, final boolean isChatAble) {
public static ChatRoomResponse of(final ChatRoomMapper mapper, final boolean isChatAble, List<ChatRoomUserMapper> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -29,6 +32,13 @@ public static List<ChatRoomPreviewResponse> makePreviewResponseList() {
}

public static ChatRoomResponse make() {
return new ChatRoomResponse(chatRoomIdx,talkSubject, talkIssue, startDate, isChatAble);
List<ChatRoomUserMapper> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -12,4 +14,6 @@ public interface ChatRoomUserCustomRepository {
void updateChatRoomUserInActive(final long chatRoomIdx, final String userUuid);

void updateChatRoomUserInActiveOfBlock(final String userUuid, final String blockUserUuid);

List<ChatRoomUserMapper> findAllActiveParticipator(final long chatRoomIdx);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Long> blockUserChatRoomIdxList = queryFactory.select(chatRoomUser.chatRoomIdx)
.from(chatRoomUser)
Expand All @@ -88,4 +91,25 @@ public void updateChatRoomUserInActiveOfBlock(final String userUuid,
.execute();
}

@Override
public List<ChatRoomUserMapper> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ChatRoomUserMapper> findAllParticipator(final long chatRoomIdx) {
return chatRoomUserRepository.findAllActiveParticipator(chatRoomIdx);
}
}

0 comments on commit 009f4fd

Please sign in to comment.