-
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.
feat: 메시지 저장을 위한 MongoDB, MySQL 연동 #39
- Loading branch information
Showing
10 changed files
with
188 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,16 @@ public Message<?> preSend(@NonNull Message<?> message, @NonNull MessageChannel | |
String userId = String.valueOf(userEmail.hashCode()); | ||
String userName = String.valueOf(userId.hashCode()); | ||
|
||
// 테스트용 코드 | ||
if (userEmail.equals("[email protected]")) { | ||
userId = "1"; | ||
userName = "로미오"; | ||
} | ||
if (userEmail.equals("[email protected]")) { | ||
userId = "2"; | ||
userName = "줄리엣"; | ||
} | ||
|
||
// STOMP 패킷 헤더에 유저 ID와 유저 이름 추가 | ||
accessor.addNativeHeader("userId", userId); | ||
accessor.addNativeHeader("userName", userName); | ||
|
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
9 changes: 9 additions & 0 deletions
9
service-chat/src/main/java/com/team13/servicechat/repository/ChatroomMessagesRepository.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,9 @@ | ||
package com.team13.servicechat.repository; | ||
|
||
import com.team13.servicechat.entity.ChatroomMessages; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ChatroomMessagesRepository extends CrudRepository<ChatroomMessages, Long> { | ||
} |
9 changes: 9 additions & 0 deletions
9
service-chat/src/main/java/com/team13/servicechat/repository/ChatroomsRepository.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,9 @@ | ||
package com.team13.servicechat.repository; | ||
|
||
import com.team13.servicechat.entity.Chatrooms; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ChatroomsRepository extends MongoRepository<Chatrooms, String> { | ||
} |
26 changes: 26 additions & 0 deletions
26
service-chat/src/main/java/com/team13/servicechat/service/ChatroomMessagesService.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,26 @@ | ||
package com.team13.servicechat.service; | ||
|
||
import com.team13.servicechat.entity.ChatroomMessages; | ||
import com.team13.servicechat.repository.ChatroomMessagesRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatroomMessagesService { | ||
|
||
private final ChatroomMessagesRepository repository; | ||
|
||
// 특정 채팅방의 메시지 목록 가져오기 | ||
public List<ChatroomMessages> getAllMessagesByChatroomId(String chatroomId) { | ||
return List.of(); | ||
} | ||
|
||
// 채팅방 메시지 저장 | ||
public ChatroomMessages saveMessage(ChatroomMessages message) { | ||
return repository.save(message); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
service-chat/src/main/java/com/team13/servicechat/service/ChatroomsService.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,30 @@ | ||
package com.team13.servicechat.service; | ||
|
||
import com.team13.servicechat.entity.Chatrooms; | ||
import com.team13.servicechat.repository.ChatroomsRepository; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatroomsService { | ||
|
||
private final ChatroomsRepository repository; // 채팅방 메시지 데이터를 저장하는 레포지토리 | ||
|
||
@PostConstruct | ||
private void init() { | ||
// 테스트 전용 채팅방이 존재하지 않는 경우, 채팅방 생성 | ||
if (!repository.existsById("test-chatroom")) { | ||
repository.save(Chatrooms.builder() | ||
.id("test-chatroom") | ||
.postsId(0) | ||
.messageIds(new ArrayList<>()) | ||
.usersIds(new ArrayList<>()) | ||
.build()); | ||
} | ||
} | ||
|
||
} |
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