-
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.
Merge pull request #24 from Domitory-CheckMate/feature/5-chat
[feat] 채팅기능
- Loading branch information
Showing
40 changed files
with
1,364 additions
and
6 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
55 changes: 55 additions & 0 deletions
55
src/main/java/org/gachon/checkmate/domain/chat/controller/ChatController.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,55 @@ | ||
package org.gachon.checkmate.domain.chat.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.chat.dto.MessageType; | ||
import org.gachon.checkmate.domain.chat.dto.request.ChatListRequestDto; | ||
import org.gachon.checkmate.domain.chat.dto.request.ChatRequestDto; | ||
import org.gachon.checkmate.domain.chat.dto.response.*; | ||
import org.gachon.checkmate.domain.chat.service.ChatService; | ||
import org.springframework.messaging.handler.annotation.Header; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.messaging.simp.SimpMessageSendingOperations; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class ChatController { | ||
|
||
private final ChatService chatService; | ||
|
||
private final SimpMessageSendingOperations sendingOperations; | ||
|
||
// 채팅 전송 | ||
@MessageMapping("/chat") | ||
public void sendChat(@Header("simpSessionAttributes") Map<String, Object> simpSessionAttributes, | ||
@Payload final ChatRequestDto request) { | ||
ChatResponseDto response = chatService.sendChat(simpSessionAttributes, request); | ||
sendingOperations.convertAndSend("/queue/chat/"+simpSessionAttributes.get("roomId"), SocketBaseResponse.of(MessageType.CHAT, response)); | ||
} | ||
|
||
// 채팅방 정보 조회 | ||
@MessageMapping("/room-list") | ||
public void getChatRoomList(@Header("simpSessionAttributes") Map<String, Object> simpSessionAttributes) { | ||
ChatRoomListResponseDto response = chatService.getChatRoomList(simpSessionAttributes); | ||
sendingOperations.convertAndSend("/queue/user/"+simpSessionAttributes.get("userId"), SocketBaseResponse.of(MessageType.ROOM_LIST, response)); | ||
} | ||
|
||
// 이전 채팅 불러오기 | ||
@MessageMapping("/chat-list") | ||
public void getChatList(@Header("simpSessionAttributes") Map<String, Object> simpSessionAttributes, | ||
@Payload final ChatListRequestDto request) { | ||
final ChatListResponseDto response = chatService.getChatList(simpSessionAttributes, request); | ||
sendingOperations.convertAndSend("/queue/user/" + simpSessionAttributes.get("userId"), SocketBaseResponse.of(MessageType.CHAT_LIST, response)); | ||
} | ||
|
||
// 채팅방 입장하기 | ||
@MessageMapping("/room-enter") | ||
public void enterRoom(@Header("simpSessionAttributes") Map<String, Object> simpSessionAttributes, | ||
@Payload final ChatListRequestDto request) { | ||
ChatRoomEnterResponseDto response = chatService.enterChatRoom(simpSessionAttributes, request); | ||
sendingOperations.convertAndSend("/queue/chat/" + response.chatRoomId(), SocketBaseResponse.of(MessageType.ROOM_ENTER, response)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/gachon/checkmate/domain/chat/dto/ChatLastMessageDto.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,25 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
import lombok.Builder; | ||
import org.gachon.checkmate.domain.chat.entity.Chat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record ChatLastMessageDto ( | ||
String content, | ||
LocalDateTime sendTime | ||
) { | ||
public static ChatLastMessageDto of(Chat chat) { | ||
return ChatLastMessageDto.builder() | ||
.content(chat.getContent()) | ||
.sendTime(chat.getSendTime()) | ||
.build(); | ||
} | ||
public static ChatLastMessageDto createEmptyChat() { | ||
return ChatLastMessageDto.builder() | ||
.content(null) | ||
.sendTime(null) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/gachon/checkmate/domain/chat/dto/ChatMessageDto.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,24 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
|
||
import lombok.Builder; | ||
import org.gachon.checkmate.domain.chat.entity.Chat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record ChatMessageDto ( | ||
Long userId, | ||
String content, | ||
Boolean isRead, | ||
LocalDateTime sendTime | ||
) { | ||
public static ChatMessageDto of(Chat chat) { | ||
return ChatMessageDto.builder() | ||
.userId(chat.getSenderId()) | ||
.content(chat.getContent()) | ||
.isRead(chat.getIsRead()) | ||
.sendTime(chat.getSendTime()) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/gachon/checkmate/domain/chat/dto/ChatRoomListDto.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,19 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
import lombok.Builder; | ||
|
||
|
||
@Builder | ||
public record ChatRoomListDto( | ||
ChatLastMessageDto lastChatInfo, | ||
Long notReadCount, | ||
ChatRoomListUserInfoDto userInfo | ||
) { | ||
public static ChatRoomListDto of(ChatLastMessageDto lastChatInfo, Long notReadCount, ChatRoomListUserInfoDto chatRoomListUserInfoDto) { | ||
return ChatRoomListDto.builder() | ||
.lastChatInfo(lastChatInfo) | ||
.notReadCount(notReadCount) | ||
.userInfo(chatRoomListUserInfoDto) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/gachon/checkmate/domain/chat/dto/ChatRoomListUserInfoDto.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,25 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import org.gachon.checkmate.domain.member.entity.GenderType; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record ChatRoomListUserInfoDto( | ||
Long userId, | ||
String name, | ||
String profile, | ||
String major, | ||
GenderType gender, | ||
LocalDate endDate | ||
) { | ||
@QueryProjection | ||
public ChatRoomListUserInfoDto(Long userId, String name, String profile, String major, GenderType gender, LocalDate endDate) { | ||
this.userId = userId; | ||
this.name = name; | ||
this.profile = profile; | ||
this.major = major; | ||
this.gender = gender; | ||
this.endDate = endDate; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/gachon/checkmate/domain/chat/dto/ChatUserInfoDto.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,24 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record ChatUserInfoDto( | ||
Long userId, | ||
String name, | ||
String profile, | ||
Long postId, | ||
String title, | ||
LocalDate endDate | ||
) { | ||
@QueryProjection | ||
public ChatUserInfoDto(Long userId, String name, String profile, Long postId, String title, LocalDate endDate) { | ||
this.userId = userId; | ||
this.name = name; | ||
this.profile = profile; | ||
this.postId = postId; | ||
this.title = title; | ||
this.endDate = endDate; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/gachon/checkmate/domain/chat/dto/MessageType.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,17 @@ | ||
package org.gachon.checkmate.domain.chat.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public enum MessageType { | ||
CHAT("CHAT"), | ||
NEW_CHAT_NOTIFICATION("NEW_CHAT_NOTIFICATION"), | ||
ROOM_ENTER("ROOM_ENTER"), | ||
ROOM_LIST("ROOM_LIST"), | ||
CHAT_LIST("CHAT_LIST"); | ||
|
||
private final String desc; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/gachon/checkmate/domain/chat/dto/request/ChatListRequestDto.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,13 @@ | ||
package org.gachon.checkmate.domain.chat.dto.request; | ||
|
||
public record ChatListRequestDto( | ||
Long otherUserId, | ||
Integer pageNumber, | ||
Integer pageSize | ||
) { | ||
public ChatListRequestDto(Long otherUserId, Integer pageNumber, Integer pageSize) { | ||
this.otherUserId = otherUserId; | ||
this.pageNumber = (pageNumber != null) ? pageNumber : 0; | ||
this.pageSize = pageSize != null ? pageSize : 20; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/org/gachon/checkmate/domain/chat/dto/request/ChatRequestDto.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,6 @@ | ||
package org.gachon.checkmate.domain.chat.dto.request; | ||
|
||
public record ChatRequestDto( | ||
String content | ||
) { | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/gachon/checkmate/domain/chat/dto/response/ChatListResponseDto.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,44 @@ | ||
package org.gachon.checkmate.domain.chat.dto.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.gachon.checkmate.domain.chat.dto.ChatMessageDto; | ||
import org.gachon.checkmate.domain.chat.dto.ChatUserInfoDto; | ||
import org.gachon.checkmate.domain.chat.entity.Chat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
public class ChatListResponseDto{ | ||
|
||
private String chatRoomId; | ||
|
||
private ChatUserInfoDto chatUserInfoDto; | ||
|
||
@Builder.Default | ||
private List<ChatMessageDto> chatMessageList = new ArrayList<>(); | ||
|
||
@Builder.Default | ||
private Boolean hasNextPage = null; | ||
|
||
@Builder.Default | ||
private Integer pageNumber = null; | ||
|
||
public static ChatListResponseDto of(String chatRoomId, ChatUserInfoDto chatUserInfoDto) { | ||
return ChatListResponseDto.builder() | ||
.chatRoomId(chatRoomId) | ||
.chatUserInfoDto(chatUserInfoDto) | ||
.build(); | ||
} | ||
|
||
public void addChatMessage(Chat chat) { | ||
this.chatMessageList.add(ChatMessageDto.of(chat)); | ||
} | ||
|
||
public void updatePageInfo(Boolean hasNextPage, Integer pageNumber) { | ||
this.hasNextPage = hasNextPage; | ||
this.pageNumber = pageNumber; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/gachon/checkmate/domain/chat/dto/response/ChatResponseDto.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,23 @@ | ||
package org.gachon.checkmate.domain.chat.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.gachon.checkmate.domain.chat.entity.Chat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record ChatResponseDto ( | ||
Long senderId, | ||
String content, | ||
Boolean isRead, | ||
LocalDateTime sendTime | ||
) { | ||
public static ChatResponseDto of(Chat chat) { | ||
return ChatResponseDto.builder() | ||
.senderId(chat.getSenderId()) | ||
.content(chat.getContent()) | ||
.isRead(chat.getIsRead()) | ||
.sendTime(chat.getSendTime()) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/gachon/checkmate/domain/chat/dto/response/ChatRoomEnterResponseDto.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,16 @@ | ||
package org.gachon.checkmate.domain.chat.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ChatRoomEnterResponseDto ( | ||
Long userId, | ||
String chatRoomId | ||
) { | ||
public static ChatRoomEnterResponseDto of(Long userId, String chatRoomId) { | ||
return ChatRoomEnterResponseDto.builder() | ||
.userId(userId) | ||
.chatRoomId(chatRoomId) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/gachon/checkmate/domain/chat/dto/response/ChatRoomListResponseDto.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,18 @@ | ||
package org.gachon.checkmate.domain.chat.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.gachon.checkmate.domain.chat.dto.ChatRoomListDto; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Builder | ||
public record ChatRoomListResponseDto( | ||
List<ChatRoomListDto> chatRoomList | ||
) { | ||
public static ChatRoomListResponseDto of(List<ChatRoomListDto> chatRoomListDto) { | ||
return ChatRoomListResponseDto.builder() | ||
.chatRoomList(chatRoomListDto) | ||
.build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/gachon/checkmate/domain/chat/dto/response/NewChatResponseDto.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,23 @@ | ||
package org.gachon.checkmate.domain.chat.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.gachon.checkmate.domain.chat.entity.Chat; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record NewChatResponseDto( | ||
String chatRoomId, | ||
Long senderId, | ||
String content, | ||
LocalDateTime sendTime | ||
) { | ||
public static NewChatResponseDto of(Chat chat) { | ||
return NewChatResponseDto.builder() | ||
.chatRoomId(chat.getChatRoomId()) | ||
.senderId(chat.getSenderId()) | ||
.content(chat.getContent()) | ||
.sendTime(chat.getSendTime()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.