forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #57 from kookmin-sw/feat/chatreadapi
[Feat/Refactor] 채팅 부가기능 API 작성
- Loading branch information
Showing
27 changed files
with
731 additions
and
110 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
96 changes: 96 additions & 0 deletions
96
src/main/java/capstone/facefriend/chat/controller/interceptor/FilterChannelInterceptor.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,96 @@ | ||
package capstone.facefriend.chat.controller.interceptor; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.MessageChannel; | ||
import org.springframework.messaging.simp.stomp.StompCommand; | ||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
import org.springframework.messaging.support.ChannelInterceptor; | ||
import org.springframework.messaging.support.MessageHeaderAccessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class FilterChannelInterceptor implements ChannelInterceptor { | ||
|
||
private static final String BEARER_PREFIX = "Bearer "; | ||
|
||
@Override | ||
public Message<?> preSend(Message<?> message, MessageChannel channel) { | ||
|
||
log.info("Stomp Handler 실행"); | ||
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); | ||
StompHeaderAccessor headerAccessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); | ||
|
||
StompCommand command = headerAccessor.getCommand(); | ||
String destination = headerAccessor.getDestination(); | ||
String subscribeUrl = headerAccessor.getSubscriptionId(); | ||
String sessionId = headerAccessor.getSessionId(); | ||
Object payload = message.getPayload(); | ||
String messageHeaders = String.valueOf(accessor.getMessageHeaders()); | ||
String messageType = String.valueOf(accessor.getMessageType()); | ||
|
||
log.info("Command: {}", command); | ||
log.info("Destination: {}", destination); | ||
log.info("Subscription ID: {}", subscribeUrl); | ||
log.info("Session ID: {}", sessionId); | ||
log.info("Payload: {}", payload.toString()); | ||
log.info("Message Type: {}", messageType); | ||
log.info("Message Headers: {}", messageHeaders.toString()); | ||
|
||
|
||
String authorizationHeader = headerAccessor.getFirstNativeHeader("Authorization"); | ||
if (headerAccessor.getCommand() == StompCommand.CONNECT) { | ||
log.info("Command: {}", command); | ||
log.info("Destination: {}", destination); | ||
log.info("Subscription ID: {}", subscribeUrl); | ||
log.info("Session ID: {}", sessionId); | ||
log.info("Payload: {}", payload.toString()); | ||
log.info("Message Type: {}", messageType); | ||
log.info("Message Headers: {}", messageHeaders.toString()); | ||
// String token = authorizationHeader.substring(BEARER_PREFIX.length()); | ||
// log.info("token: {}", token); | ||
// if (token == null) try { | ||
// throw new AccessDeniedException(""); | ||
// } catch (AccessDeniedException e) { | ||
// throw new RuntimeException(e); | ||
// } | ||
} | ||
|
||
if (headerAccessor.getCommand() == StompCommand.SUBSCRIBE) { | ||
log.info("Command: {}", command); | ||
log.info("Destination: {}", destination); | ||
log.info("Subscription ID: {}", subscribeUrl); | ||
log.info("Session ID: {}", sessionId); | ||
log.info("Payload: {}", payload.toString()); | ||
log.info("Message Type: {}", messageType); | ||
log.info("Message Headers: {}", messageHeaders.toString()); | ||
} | ||
|
||
if (headerAccessor.getCommand() == StompCommand.DISCONNECT) { | ||
log.info("Command: {}", command); | ||
log.info("Destination: {}", destination); | ||
log.info("Subscription ID: {}", subscribeUrl); | ||
log.info("Session ID: {}", sessionId); | ||
log.info("Payload: {}", payload.toString()); | ||
log.info("Message Type: {}", messageType); | ||
log.info("Message Headers: {}", messageHeaders.toString()); | ||
} | ||
|
||
|
||
if (headerAccessor.getCommand() == StompCommand.SEND) { | ||
log.info("Command: {}", command); | ||
log.info("Destination: {}", destination); | ||
log.info("Subscription ID: {}", subscribeUrl); | ||
log.info("Session ID: {}", sessionId); | ||
log.info("Payload: {}", payload.toString()); | ||
log.info("Message Type: {}", messageType); | ||
log.info("Message Headers: {}", messageHeaders.toString()); | ||
} | ||
|
||
|
||
return message; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/capstone/facefriend/chat/domain/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,25 @@ | ||
package capstone.facefriend.chat.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@RedisHash("ChatRoom") | ||
@Slf4j | ||
public class ChatRoomInfo { | ||
@Id | ||
private String chatRoomInfoId; | ||
|
||
@Column(name = "enterTime", nullable = false) | ||
private LocalDateTime enterTime; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/capstone/facefriend/chat/domain/SocketInfo.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 capstone.facefriend.chat.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import lombok.*; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@RedisHash("SocketInfo") | ||
public class SocketInfo { | ||
@Id | ||
private Long memberId; | ||
|
||
@Column(name = "connectTime", nullable = false) | ||
private LocalDateTime connectTime; | ||
} |
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
7 changes: 6 additions & 1 deletion
7
src/main/java/capstone/facefriend/chat/repository/ChatMessageRepository.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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package capstone.facefriend.chat.repository; | ||
|
||
import capstone.facefriend.chat.domain.ChatMessage; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
|
||
public interface ChatMessageRepository extends JpaRepository<ChatMessage, Long> { | ||
ChatMessage findFirstByChatRoomIdOrderBySendTimeDesc(Long roomId); | ||
ChatMessage save(ChatMessage chatMessage); | ||
|
||
List<ChatMessage> findChatMessagesByChatRoom_IdAndSendTimeBefore(Long roomId, LocalDateTime time, Pageable pageable); | ||
List<ChatMessage> findChatMessagesByChatRoomId(Long roomId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/capstone/facefriend/chat/repository/ChatRoomInfoRedisRepository.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 capstone.facefriend.chat.repository; | ||
|
||
import capstone.facefriend.chat.domain.ChatRoomInfo; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ChatRoomInfoRedisRepository extends CrudRepository<ChatRoomInfo, String> { | ||
Optional<ChatRoomInfo> findById(String chatRoomInfoId); | ||
} |
Oops, something went wrong.