Skip to content

Commit

Permalink
Bug/#187 chatroom 조회 오류 수정 (#188)
Browse files Browse the repository at this point in the history
* [FIX] 채팅방 조회 오류 수정

* [FIX] 읽기 전용 트랜잭션 수정
  • Loading branch information
tidavid1 authored Feb 27, 2024
1 parent 55f9258 commit deb0ba9
Show file tree
Hide file tree
Showing 3 changed files with 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public UserProfileResponse getUserProfile(Long userId) {
}

// TODO: 이후 AchievementException 구현 시 추가 필요!
@Transactional
public UserUpdateRes updateUserInfos(Long userId, UserUpdateReq request) {
User user = userCommonService.getUserById(userId);
Achievement achievement = achievementRepository.findById(request.getAchievementId())
Expand Down

0 comments on commit deb0ba9

Please sign in to comment.