Skip to content

Commit

Permalink
Merge pull request #7 from catchroom/feature/fix-message
Browse files Browse the repository at this point in the history
Feature/fix message
  • Loading branch information
sungjiwoon authored Jan 18, 2024
2 parents 7165ef4 + d408e3d commit 5495afe
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
* ๊ธฐ์กด์—๋Š” ์‹ ๊ทœ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ ์‹œ ๋ฌด์กฐ๊ฑด ์ƒˆ๋กœ์šด ChannelTopic์„ ์ƒ์„ฑํ•˜๊ณ  ์ƒˆ๋กœ์šด redisListener์™€ ์—ฐ๋™ํ•˜์—ฌ ์ž‘์—….
* ๊ทธ๋Ÿฌ๋‚˜ ์ด๋ฐฉ๋ฒ•์€ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ์ž์›์„ ๋‚ญ๋น„ํ•˜๋Š” ๋‹จ์ ์ด ์กด์žฌํ•จ.
* ๊ทธ๋ž˜์„œ ChannelTopic ๊ณผ redisListener ์ผ์›ํ™” ์ž‘์—… ์ง„ํ–‰์œผ๋กœ ๋ณ€๊ฒฝ.
* redisPublisher ์‚ญ์ œ => redisTemplate ๋Œ€์ฒด
*/

@RequiredArgsConstructor
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class ChatController {
@MessageMapping("/chat/message")
public void message(ChatMessageDto message) {
log.info("chatController Sender: {}", message.getSender());
chatMongoService.save(message);
message.setUserCount(chatRoomRepository.getUserCount(message.getRoomId()));
chatService.sendChatMessage(message);
ChatMessageDto chatMessageDto = chatMongoService.save(message);
message.setUserCount(chatRoomRepository.getUserCount(chatMessageDto.getRoomId()));
chatService.sendChatMessage(chatMessageDto);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.catchroom.chat.message.entity.ChatMessage;
import com.catchroom.chat.message.type.MessageType;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -20,13 +21,15 @@ public class ChatMessageDto {
private String roomId; // ๋ฐฉ ๋ฒˆํ˜ธ
private String sender; // ์ฑ„ํŒ…์„ ๋ณด๋‚ธ ์‚ฌ๋žŒ
private String message; // ๋ฉ”์‹œ์ง€
private String time;
private long userCount; // ์ฑ„ํŒ…๋ฐฉ ์ธ์› ์ˆ˜

public static ChatMessageDto fromEntity(ChatMessage chatMessage) {
return ChatMessageDto.builder()
.type(chatMessage.getType())
.sender(chatMessage.getSender())
.roomId(chatMessage.getRoomId())
.time(chatMessage.getTime())
.message(chatMessage.getMessage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
@Document(collection = "chat")
public class ChatMessage {

// @Id
// private Long id;

private MessageType type; // ๋ฉ”์‹œ์ง€ ํƒ€์ž…
private String roomId; // ๋ฐฉ ๋ฒˆํ˜ธ
private String sender; // ์ฑ„ํŒ…์„ ๋ณด๋‚ธ ์‚ฌ๋žŒ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public class ChatMongoService {

// ์ฑ„ํŒ… ์ €์žฅ
@Transactional
public void save(ChatMessageDto chatMessageDto) {
public ChatMessageDto save(ChatMessageDto chatMessageDto) {
ChatMessage chatMessage = chatMessageRepository.save(ChatMessage.of(chatMessageDto));
log.info("save success : {}", chatMessage.getMessage());
return ChatMessageDto.fromEntity(chatMessage);
}

// ์ฑ„ํŒ… ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.catchroom.chat.global.pubsub.RedisPublisher;
import com.catchroom.chat.message.repository.ChatRoomRepository;
import com.catchroom.chat.message.type.MessageType;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -39,6 +40,7 @@ public void sendChatMessage(ChatMessageDto chatMessage) {
chatMessage.setMessage(chatMessage.getSender() + "๋‹˜์ด ๋ฐฉ์—์„œ ๋‚˜๊ฐ”์Šต๋‹ˆ๋‹ค.");
chatMessage.setSender("[์•Œ๋ฆผ]");
}

redisPublisher.publish(chatMessage);
}

Expand Down

0 comments on commit 5495afe

Please sign in to comment.