Skip to content

Commit

Permalink
[FIX] 채팅방 조회 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tidavid1 committed Feb 27, 2024
1 parent 052d038 commit 34afca2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Schema(description = "채팅방 리스트 조회 응답")
@Getter
@AllArgsConstructor
public class ChatRoomPublicRes {
@Schema(description = "프로젝트 ID")
private Long projectId;
@Schema(description = "채팅방 ID")
private String chatRoomId;
@Setter
@Schema(description = "마지막 메시지")
private String lastMessage;
@Setter
@Schema(description = "마지막 메시지 생성 시간")
private LocalDateTime lastMessageCreatedAt;
@Schema(description = "채팅방 상태")
private ChatStatus status;

private List<ChatUserInfo> profiles;

public ChatRoomPublicRes(Long projectId, String chatRoomId, ChatStatus status,
List<ChatUserInfo> profiles) {
this.projectId = projectId;
this.chatRoomId = chatRoomId;
this.status = status;
this.profiles = profiles;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.oeid.mogakgo.domain.chat.infrastructure;

import static io.oeid.mogakgo.domain.chat.entity.document.QChatRoom.chatRoom;
import static io.oeid.mogakgo.domain.user.domain.QUser.user;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomPublicRes;
import io.oeid.mogakgo.domain.chat.application.vo.ChatUserInfo;
import io.oeid.mogakgo.domain.user.domain.QUser;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -18,13 +18,15 @@ public class ChatRoomCustomRepositoryImpl implements ChatRoomCustomRepository {
private final JPAQueryFactory jpaQueryFactory;

public List<ChatRoomPublicRes> findAllChatRoomByUserId(Long userId) {

QUser sender = new QUser("sender");
QUser creator = new QUser("creator");

return jpaQueryFactory.select(
Projections.constructor(
ChatRoomPublicRes.class,
chatRoom.project.id,
chatRoom.id,
null,
null,
chatRoom.status,
Projections.list(List.of(
Projections.constructor(
Expand All @@ -42,7 +44,7 @@ public List<ChatRoomPublicRes> findAllChatRoomByUserId(Long userId) {
)
)
)
).from(chatRoom).join(chatRoom.creator, user).join(chatRoom.sender, user)
).from(chatRoom).join(chatRoom.creator, creator).join(chatRoom.sender, sender)
.where(chatRoom.creator.id.eq(userId).or(chatRoom.sender.id.eq(userId)))
.fetch();
}
Expand Down

0 comments on commit 34afca2

Please sign in to comment.