-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] : 채팅 메시지 조회 DTO에 읽음 여부 필드 추가 * [test] : DTO에 읽음 여부 필드 추가 반영 * [feat] : 채팅방 목록 조회용 dto 추가 * [feat] : 채팅방 query repository 추가 * [test] : 채팅방 query repository 테스트 * [feat] : 채팅방 최근 메시지 DTO 추가 * [feat] : mongoDB로 각 채팅방별 최근 메시지 조회 * [test] : mongoDB로 각 채팅방별 최근 메시지 조회 테스트 * [feat] : 채팅방 목록 조회 DTO 추가 * [feat] : 채팅방 목록 조회 비즈니스 로직 추가 * [feat] : 채팅방 목록 조회 API 메서드 작성 * [test] : 채팅방 목록 조회 API 통합 테스트 * [style] : 코드 리포멧팅 * [feat] : 예외 메세지 수정 * [feat] : 채팅 메시지 요청 필드명 수정
- Loading branch information
Showing
20 changed files
with
400 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dnd.gongmuin.chat.dto.response; | ||
|
||
import com.dnd.gongmuin.member.domain.JobGroup; | ||
import com.querydsl.core.annotations.QueryProjection; | ||
|
||
public record ChatRoomInfo( | ||
Long chatRoomId, | ||
Long partnerId, | ||
String partnerNickname, | ||
String partnerJobGroup, | ||
int partnerProfileImageNo | ||
) { | ||
@QueryProjection | ||
public ChatRoomInfo( | ||
Long chatRoomId, | ||
Long partnerId, | ||
String partnerNickname, | ||
JobGroup partnerJobGroup, | ||
int partnerProfileImageNo | ||
) { | ||
this( | ||
chatRoomId, | ||
partnerId, | ||
partnerNickname, | ||
partnerJobGroup.getLabel(), | ||
partnerProfileImageNo | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/dnd/gongmuin/chat/dto/response/ChatRoomSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.dnd.gongmuin.chat.dto.response; | ||
|
||
import com.dnd.gongmuin.question_post.dto.response.MemberInfo; | ||
|
||
public record ChatRoomSimpleResponse( | ||
Long chatRoomId, | ||
MemberInfo chatPartner, | ||
String latestMessage, | ||
String messageType, | ||
String messageCreatedAt | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/gongmuin/chat/dto/response/LatestChatMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dnd.gongmuin.chat.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record LatestChatMessage( | ||
Long chatRoomId, | ||
String content, | ||
String type, | ||
LocalDateTime createdAt | ||
) { | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/dnd/gongmuin/chat/repository/ChatMessageQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.dnd.gongmuin.chat.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationOperation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.dnd.gongmuin.chat.dto.response.LatestChatMessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class ChatMessageQueryRepository { | ||
|
||
private final MongoTemplate mongoTemplate; | ||
|
||
public List<LatestChatMessage> findLatestChatByChatRoomIds(List<Long> chatRoomIds) { | ||
AggregationOperation sort = Aggregation.sort(Sort.Direction.DESC, "createdAt"); | ||
AggregationOperation match = Aggregation.match(Criteria.where("chatRoomId").in(chatRoomIds)); | ||
AggregationOperation group = Aggregation.group("chatRoomId") | ||
.first("createdAt").as("createdAt") | ||
.first("content").as("content") | ||
.first("type").as("type"); | ||
AggregationOperation project = Aggregation.project() | ||
.and("_id").as("chatRoomId") | ||
.and("createdAt").as("createdAt") | ||
.and("content").as("content") | ||
.and("type").as("type"); | ||
Aggregation aggregation = Aggregation.newAggregation(sort, match, group, project); | ||
AggregationResults<LatestChatMessage> results = mongoTemplate.aggregate(aggregation, "chat_messages", | ||
LatestChatMessage.class); | ||
return results.getMappedResults(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.dnd.gongmuin.chat.repository; | ||
|
||
import java.util.List; | ||
|
||
import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; | ||
import com.dnd.gongmuin.member.domain.Member; | ||
|
||
public interface ChatRoomQueryRepository { | ||
List<ChatRoomInfo> getChatRoomsByMember(Member member); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/dnd/gongmuin/chat/repository/ChatRoomQueryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.dnd.gongmuin.chat.repository; | ||
|
||
import static com.dnd.gongmuin.chat.domain.QChatRoom.*; | ||
|
||
import java.util.List; | ||
|
||
import com.dnd.gongmuin.chat.dto.response.ChatRoomInfo; | ||
import com.dnd.gongmuin.chat.dto.response.QChatRoomInfo; | ||
import com.dnd.gongmuin.member.domain.Member; | ||
import com.querydsl.core.types.dsl.CaseBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ChatRoomQueryRepositoryImpl implements ChatRoomQueryRepository { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
public List<ChatRoomInfo> getChatRoomsByMember(Member member) { | ||
return queryFactory | ||
.select(new QChatRoomInfo( | ||
chatRoom.id, | ||
new CaseBuilder() | ||
.when(chatRoom.inquirer.id.eq(member.getId())) | ||
.then(chatRoom.answerer.id) | ||
.otherwise(chatRoom.inquirer.id), | ||
new CaseBuilder() | ||
.when(chatRoom.inquirer.id.eq(member.getId())) | ||
.then(chatRoom.answerer.nickname) | ||
.otherwise(chatRoom.inquirer.nickname), | ||
new CaseBuilder() | ||
.when(chatRoom.inquirer.id.eq(member.getId())) | ||
.then(chatRoom.answerer.jobGroup) | ||
.otherwise(chatRoom.inquirer.jobGroup), | ||
new CaseBuilder() | ||
.when(chatRoom.inquirer.id.eq(member.getId())) | ||
.then(chatRoom.answerer.profileImageNo) | ||
.otherwise(chatRoom.inquirer.profileImageNo) | ||
)) | ||
.from(chatRoom) | ||
.where(chatRoom.inquirer.id.eq(member.getId()) | ||
.or(chatRoom.answerer.id.eq(member.getId()))) | ||
.fetch(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.