-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#29 채팅 관련 로직 구현 #183
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8fa3862
Feat: 채팅방 및 관련기능, 채팅 메세지 전송을 위한 웹소켓 설정
runtime-zer0 63714f3
Feat: 채팅방 관련 로직을 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 ee55eae
Feat: 채팅방에 참여한 사용자 정보 관리 로직 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 51fc1f9
Feat: 채팅 메세지 발행 및 전송, 메세지 수신 구현을 위한 레포지토리 및 DTO 구현
runtime-zer0 d0dee9a
Feat: 채팅방 입장, 퇴장 관련 로직을 구현하기 위한 비즈니스 로직 구현
runtime-zer0 ec84270
Feat: 메세지 발행 및 전송, 수신 관련 로직을 구현하기 위한 비즈니스 로직 및 유틸 클래스 구현
runtime-zer0 8392c8e
Feat: 채팅방 입장/퇴장 요청을 캐치하기 위한 컨트롤러 구현
runtime-zer0 8df6cef
Feat: 채팅 메세지 발행 및 전송, 채팅방 메세지 조회 요청을 캐치하기 위한 컨트롤러 구현
runtime-zer0 4686033
Feat: 채팅방 정보와 연관된 모집글 요약 정보 조희를 위한 로직 및 DTO 구현
runtime-zer0 c447551
Feat: 채팅방 입장/퇴장시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 84dafca
Feat: 채팅방에 입장한 사용자 관련 정보 관리시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 9db6afe
Feat: 채팅 메세지 발행 및 전송시 발생할 수 있는 예외 클래스 및 예외 핸들러 구현
runtime-zer0 b6cfb5d
Refactor: 클래스 이름 변경으로 인한 리팩토링 및 필드 이름 수정
runtime-zer0 7ac0dee
Refactor: 스프링의 단일 책임 원칙을 위한 리팩토링
runtime-zer0 42ff90c
Merge branch 'main' into feature/#29
runtime-zer0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/sumcoda/boardbuddy/dto/ChatRoomResponse.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,60 @@ | ||
package sumcoda.boardbuddy.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import sumcoda.boardbuddy.enumerate.MemberChatRoomRole; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class ChatRoomResponse { | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class InfoDTO { | ||
|
||
private Long id; | ||
|
||
private LocalDateTime joinedAt; | ||
|
||
private MemberChatRoomRole memberChatRoomRole; | ||
|
||
@Builder | ||
public InfoDTO(Long id, LocalDateTime joinedAt, MemberChatRoomRole memberChatRoomRole) { | ||
this.id = id; | ||
this.joinedAt = joinedAt; | ||
this.memberChatRoomRole = memberChatRoomRole; | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class ValidateDTO { | ||
|
||
private Long id; | ||
|
||
@Builder | ||
public ValidateDTO(Long id) { | ||
this.id = id; | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class ChatRoomDetailsDTO { | ||
|
||
private Long chatRoomId; | ||
|
||
private GatherArticleResponse.SimpleInfoDTO gatherArticleSimpleInfo; | ||
|
||
private ChatMessageResponse.LastChatMessageInfoDTO lastChatMessageInfo; | ||
|
||
@Builder | ||
public ChatRoomDetailsDTO(Long chatRoomId, GatherArticleResponse.SimpleInfoDTO gatherArticleSimpleInfo, ChatMessageResponse.LastChatMessageInfoDTO lastChatMessageInfo) { | ||
this.chatRoomId = chatRoomId; | ||
this.gatherArticleSimpleInfo = gatherArticleSimpleInfo; | ||
this.lastChatMessageInfo = lastChatMessageInfo; | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/sumcoda/boardbuddy/repository/chatRoom/ChatRoomRepository.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,14 @@ | ||
package sumcoda.boardbuddy.repository.chatRoom; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import sumcoda.boardbuddy.entity.ChatRoom; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long>, ChatRoomRepositoryCustom { | ||
Optional<ChatRoom> findByGatherArticleId(Long gatherArticleId); | ||
|
||
Optional<ChatRoom> findById(Long chatRoomId); | ||
|
||
boolean existsById(Long chatRoomId); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/sumcoda/boardbuddy/repository/chatRoom/ChatRoomRepositoryCustom.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,15 @@ | ||
package sumcoda.boardbuddy.repository.chatRoom; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import sumcoda.boardbuddy.dto.ChatRoomResponse; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface ChatRoomRepositoryCustom { | ||
|
||
Optional<ChatRoomResponse.ValidateDTO> findValidateDTOByGatherArticleId(Long gatherArticleId); | ||
|
||
List<ChatRoomResponse.ChatRoomDetailsDTO> findChatRoomDetailsListByUsername(String username); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/sumcoda/boardbuddy/repository/chatRoom/ChatRoomRepositoryCustomImpl.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,79 @@ | ||
package sumcoda.boardbuddy.repository.chatRoom; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.JPAExpressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import sumcoda.boardbuddy.dto.ChatMessageResponse; | ||
import sumcoda.boardbuddy.dto.ChatRoomResponse; | ||
import sumcoda.boardbuddy.dto.GatherArticleResponse; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static sumcoda.boardbuddy.entity.QChatMessage.chatMessage; | ||
import static sumcoda.boardbuddy.entity.QChatRoom.*; | ||
import static sumcoda.boardbuddy.entity.QGatherArticle.gatherArticle; | ||
import static sumcoda.boardbuddy.entity.QMember.member; | ||
import static sumcoda.boardbuddy.entity.QMemberChatRoom.memberChatRoom; | ||
|
||
@RequiredArgsConstructor | ||
public class ChatRoomRepositoryCustomImpl implements ChatRoomRepositoryCustom { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
|
||
/** | ||
* 특정 모집글 Id로 ChatRoom 검증 정보 조회 | ||
* | ||
* @param gatherArticleId 모집글 Id | ||
* @return ChatRoom 검증 정보가 포함된 ValidateDTO 객체 | ||
**/ | ||
@Override | ||
public Optional<ChatRoomResponse.ValidateDTO> findValidateDTOByGatherArticleId(Long gatherArticleId) { | ||
return Optional.ofNullable(jpaQueryFactory.select(Projections.fields(ChatRoomResponse.ValidateDTO.class, | ||
chatRoom.id)) | ||
.from(chatRoom) | ||
.join(chatRoom.gatherArticle, gatherArticle) | ||
.where(gatherArticle.id.eq(gatherArticleId)) | ||
.fetchOne()); | ||
} | ||
|
||
/** | ||
* 특정 사용자 아이디 사용자가 속한 채팅방 상세 정보 목록 조회 | ||
* | ||
* @param username 사용자 아이디 | ||
* @return 사용자가 속한 채팅방의 상세 정보 목록 | ||
**/ | ||
@Override | ||
public List<ChatRoomResponse.ChatRoomDetailsDTO> findChatRoomDetailsListByUsername(String username) { | ||
return jpaQueryFactory | ||
.select(Projections.fields(ChatRoomResponse.ChatRoomDetailsDTO.class, | ||
chatRoom.id, | ||
Projections.constructor(GatherArticleResponse.SimpleInfoDTO.class, | ||
gatherArticle.id, | ||
gatherArticle.title, | ||
gatherArticle.meetingLocation, | ||
gatherArticle.currentParticipants | ||
).as("gatherArticleSimpleInfo"), | ||
Projections.fields(ChatMessageResponse.LastChatMessageInfoDTO.class, | ||
chatMessage.content, | ||
chatMessage.createdAt.as("sentAt") | ||
) | ||
)) | ||
.from(chatRoom) | ||
.leftJoin(chatRoom.chatMessages, chatMessage) | ||
.join(chatRoom.gatherArticle, gatherArticle) | ||
.join(chatRoom.memberChatRooms, memberChatRoom) | ||
.join(memberChatRoom.member, member) | ||
.where(member.username.eq(username) | ||
.and(chatMessage.createdAt.eq( | ||
JPAExpressions | ||
.select(chatMessage.createdAt.max()) | ||
.from(chatMessage) | ||
.where(chatMessage.chatRoom.id.eq(chatRoom.id)) | ||
)) | ||
) | ||
Comment on lines
+69
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 서브 쿼리를 이렇게 활용하는군요! |
||
.fetch(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
필드 직접 접근 방식으로 컨벤션을 유지하면 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다.