diff --git a/src/main/java/capstone/facefriend/chat/config/RedisConfig.java b/src/main/java/capstone/facefriend/chat/config/RedisConfig.java index 07af53c8f7..7110fed66c 100644 --- a/src/main/java/capstone/facefriend/chat/config/RedisConfig.java +++ b/src/main/java/capstone/facefriend/chat/config/RedisConfig.java @@ -16,7 +16,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; -import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration @@ -27,7 +27,6 @@ public class RedisConfig { @Value("${spring.data.redis.port}") private int redisPort; - @Bean public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = @@ -43,7 +42,6 @@ public RedisMessageListenerContainer redisMessageListenerContainer( ) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); - // RedisMessageListenerContainer 에 Bean 으로 등록한 listenerAdapter, channelTopic 추가 container.addMessageListener(listenerAdapter, channelTopic); return container; } @@ -53,12 +51,8 @@ public RedisTemplate redisTemplate(RedisConnectionFactory redisC RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); - // Jackson2JsonRedisSerializer를 사용하여 RedisTemplate 설정 - Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Object.class); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); // Java 8 시간 모듈 등록 - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // 날짜를 타임스탬프로 변환하지 않도록 설정 - serializer.setObjectMapper(objectMapper); + // GenericJackson2JsonRedisSerializer를 사용하여 RedisTemplate 설정 + GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(objectMapper()); // 문자열 직렬화 설정 redisTemplate.setKeySerializer(new StringRedisSerializer()); @@ -81,6 +75,15 @@ public MessageListenerAdapter listenerAdapter(RedisSubscriber subscriber) { } @Bean - public ChannelTopic channelTopic() {return new ChannelTopic("chatroom");} + public ChannelTopic channelTopic() { + return new ChannelTopic("chatroom"); + } -} \ No newline at end of file + @Bean + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + return objectMapper; + } +} diff --git a/src/main/java/capstone/facefriend/chat/controller/ChatRoomController.java b/src/main/java/capstone/facefriend/chat/controller/ChatRoomController.java index 6f9d82155a..918e2f141b 100644 --- a/src/main/java/capstone/facefriend/chat/controller/ChatRoomController.java +++ b/src/main/java/capstone/facefriend/chat/controller/ChatRoomController.java @@ -24,23 +24,6 @@ ResponseEntity> getChatRoomList( return ResponseEntity.ok(chatRoomService.getChatRoomList(memberId)); } - @PostMapping("/room/{roomId}/enter") - public ResponseEntity enterChatRoom( - @PathVariable("roomId") Long roomId, - @AuthMember Long memberId, - @RequestParam(required = false, defaultValue = "0", value = "page") int pageNo - ){ - return ResponseEntity.ok(chatRoomService.enterRoom(roomId, memberId)); - } - - @PostMapping("/room/{roomId}/exit") - public ResponseEntity exitChatRoom( - @PathVariable("roomId") Long roomId, - @AuthMember Long memberId - ){ - return ResponseEntity.ok(chatRoomService.exitRoom(roomId, memberId)); - } - @PostMapping("/room/{roomId}/left") public ResponseEntity leftChatRoom( @PathVariable("roomId") Long roomId, diff --git a/src/main/java/capstone/facefriend/chat/service/ChatRoomService.java b/src/main/java/capstone/facefriend/chat/service/ChatRoomService.java index d752f6f8f0..2f178683c7 100644 --- a/src/main/java/capstone/facefriend/chat/service/ChatRoomService.java +++ b/src/main/java/capstone/facefriend/chat/service/ChatRoomService.java @@ -166,23 +166,6 @@ public Map getChatRoomList(Long memberId) { return chatRooms; } - public ChatRoomEnterResponse enterRoom(Long roomId, Long memberId) { - String chatRoomInfoId = roomId + "/member/" + memberId; - ChatRoomInfo chatRoomInfo = new ChatRoomInfo(); - chatRoomInfo.setChatRoomInfoId(chatRoomInfoId); - chatRoomInfo.setEnterTime(LocalDateTime.now()); - chatRoomInfoRedisRepository.save(chatRoomInfo); - return ChatRoomEnterResponse.of(roomId, memberId, chatRoomInfo); - } - - public ChatRoomExitResponse exitRoom(Long roomId, Long memberId) { - String chatRoomInfoId = roomId + "/member/" + memberId; - ChatRoomInfo chatRoomInfo = findChatRoomInfo(chatRoomInfoId); - chatRoomInfoRedisRepository.delete(chatRoomInfo); - LocalDateTime exitChatRoomTime = LocalDateTime.now(); - return ChatRoomExitResponse.of(roomId, memberId, exitChatRoomTime); - } - @Transactional public String leftRoom(Long roomId, Long memberId) { ChatRoom chatRoom = findRoomById(roomId); diff --git a/src/main/java/capstone/facefriend/chat/service/RedisSubscriber.java b/src/main/java/capstone/facefriend/chat/service/RedisSubscriber.java index bad7abd6d6..17c22a621a 100644 --- a/src/main/java/capstone/facefriend/chat/service/RedisSubscriber.java +++ b/src/main/java/capstone/facefriend/chat/service/RedisSubscriber.java @@ -77,25 +77,13 @@ private Boolean isExistSubscriber(Long memberId) { private void saveUnReadMessage(String destination, MessageResponse messageResponse) { - Boolean isUnRead = redisTemplate.hasKey(destination); - log.info(isUnRead.toString()); - if (isUnRead) { - messageResponse.setMethod("connectChat"); - redisTemplate.opsForList().rightPush(destination, messageResponse); - } else { - messageResponse.setMethod("connectChat"); - redisTemplate.opsForList().rightPush(destination, messageResponse); - } + messageResponse.setMethod("connectChat"); + redisTemplate.opsForList().rightPush(destination, messageResponse); + } private void saveUnReadHeart(String destination, SendHeartResponse sendHeartResponse) { - Boolean isUnRead = redisTemplate.hasKey(destination); - if (isUnRead) { sendHeartResponse.setMethod("connectHeart"); redisTemplate.opsForList().rightPush(destination, sendHeartResponse); - } else { - sendHeartResponse.setMethod("connectHeart"); - redisTemplate.opsForList().rightPush(destination, sendHeartResponse); - } } } \ No newline at end of file