Skip to content

Commit

Permalink
Feat: UserId 멤버변수 추가, historty db조회 로직 변경 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
resource777 committed Aug 5, 2023
1 parent 93064c3 commit df16844
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,28 @@ public void sendMessage(@Payload StompMessageDto stompMessageDto, @DestinationVa
Optional<Character> character = characterService.getCharacterInfo(id);
String characterName = character.map(Character::getBotName).orElse("There is No bot to talk");

stompMessageDto.setReplyMessageId()
stompMessageDto.setUserId(username)
.setReplyMessageId()
.setMessageFrom(username)
.setMessageTo(id)
.setStatus("STARTED")
.setCharacterName(characterName);
// history 가져오기
List<StompMessageEntity> history = stompMessageService.getUserChatHistory(username, characterName);
int count = 0;
for (StompMessageEntity message : history) {
System.out.println("count++ = " + count++);
System.out.println("message.getUserId() = " + message.getUserId());
System.out.println("Message Id: " + message.getMessageId());
System.out.println("Status: " + message.getStatus());
System.out.println("Content: " + message.getContent());
System.out.println("Message From: " + message.getMessageFrom());
System.out.println("Character Name: " + message.getCharacterName());
System.out.println("CreatedAt: " + message.getCreatedAt());
System.out.println("----------------------------------");
}
// 채팅 저장
stompMessageService.save(stompMessageDto);
// history 가져오기
List<StompMessageEntity> history = stompMessageService.getUserChatHistory(username);
messageTemplate.convertAndSend("/exchange/celery/celery",
stompMessageDto.toCeleryMessageDto("inference", history));
messageTemplate.convertAndSend("/topic/" + username, stompMessageDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class StompMessageEntity {
@Id
private String id;
private String userId;
private String messageId;
private String replyMessageId;
private String status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@NoArgsConstructor
public class StompMessageDto {
private String messageId = UUID.randomUUID().toString();
private String userId;
private String replyMessageId;
private String status;
private String content;
Expand All @@ -30,6 +31,11 @@ public StompMessageDto(String status, String content, String messageFrom) {
this.messageFrom = messageFrom;
}

public StompMessageDto setUserId(String userId) {
this.userId = userId;
return this;
}

public StompMessageDto setReplyMessageId(String replyMessageId) {
this.replyMessageId = replyMessageId;
return this;
Expand Down Expand Up @@ -79,6 +85,7 @@ public CeleryMessageDto toCeleryMessageDto(String task, List<StompMessageEntity>
public StompMessageEntity toEntity() {
StompMessageEntity entity = new StompMessageEntity();
entity.setMessageId(this.messageId);
entity.setUserId(this.userId);
entity.setReplyMessageId(this.replyMessageId);
entity.setStatus(this.status);
entity.setContent(this.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

@Repository
public interface StompMessageRepository extends MongoRepository<StompMessageEntity, String> {
List<StompMessageEntity> findByMessageFromOrMessageTo(String messageFrom, String messageTo);
//List<StompMessageEntity> findByMessageFromOrMessageTo(String messageFrom, String messageTo);

List<StompMessageEntity> findByUserIdAndCharacterName(String userId, String characterName);


List<StompMessageEntity> findByMessageId(String messageId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
public class StompMessageService {
private final StompMessageRepository stompMessageRepository;

public List<StompMessageEntity> getUserChatHistory(String username) {
return stompMessageRepository.findByMessageFromOrMessageTo(username, username);
public List<StompMessageEntity> getUserChatHistory(String userId, String characterName) {
//return stompMessageRepository.findByMessageFromOrMessageTo(username, username);
return stompMessageRepository.findByUserIdAndCharacterName(userId, characterName);
}

public boolean messageExists(String messageId) {
Expand Down

0 comments on commit df16844

Please sign in to comment.