Skip to content

Commit

Permalink
✨ [Feat] socket 서버 매너평가 메시지 전송 API 요청 시 timestamp 값 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjin3395 committed Oct 13, 2024
1 parent 12d47ba commit 19ea822
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/gamegoo/scheduler/SchedulerService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gamegoo.scheduler;

import com.gamegoo.domain.chat.Chat;
import com.gamegoo.domain.matching.MatchingRecord;
import com.gamegoo.domain.matching.MatchingStatus;
import com.gamegoo.repository.matching.MatchingRecordRepository;
Expand Down Expand Up @@ -31,7 +32,7 @@ public class SchedulerService {
* 매칭 성공 1시간이 경과한 경우, 두 사용자에게 매너평가 시스템 메시지 전송
*/
@Transactional
@Scheduled(fixedRate = 1000 * 60) // 60초 주기로 실행
@Scheduled(fixedRate = 5 * 60 * 1000) // 5 * 60초 주기로 실행
public void mannerSystemMessageRun() {
// log.info("scheduler start");

Expand All @@ -47,15 +48,15 @@ public void mannerSystemMessageRun() {
).ifPresentOrElse(
chatroom -> {
// 시스템 메시지 생성 및 db 저장
chatCommandService.createAndSaveSystemChat(
Chat createdChat = chatCommandService.createAndSaveSystemChat(
chatroom, matchingRecord.getMember(), MANNER_SYSTEM_MESSAGE, null, 1);

// 매너 평가 메시지 전송 여부 업데이트
matchingRecord.updateMannerMessageSent(true);

// socket 서버에게 메시지 전송 API 요청
socketService.sendSystemMessage(matchingRecord.getMember().getId(),
chatroom.getUuid(), MANNER_SYSTEM_MESSAGE);
chatroom.getUuid(), MANNER_SYSTEM_MESSAGE, createdChat.getTimestamp());
},
() -> log.info("Chatroom not found, member ID: {}, target member ID: {}",
matchingRecord.getMember().getId(), matchingRecord.getTargetMember().getId()));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gamegoo/service/socket/SocketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public void joinSocketToChatroom(Long memberId, String chatroomUuid) {
}
}

public void sendSystemMessage(Long memberId, String chatroomUuid, String content) {
public void sendSystemMessage(Long memberId, String chatroomUuid, String content,
Long timestamp) {
String url = SOCKET_SERVER_URL + "/socket/sysmessage";
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("memberId", memberId);
requestBody.put("chatroomUuid", chatroomUuid);
requestBody.put("content", content);
requestBody.put("timestamp", timestamp);

try {
ResponseEntity<String> response = restTemplate.postForEntity(url, requestBody,
Expand Down

0 comments on commit 19ea822

Please sign in to comment.