Skip to content

Commit

Permalink
Merge pull request #290 from Gamegoo-repo/feat/288
Browse files Browse the repository at this point in the history
[Feat/288] ๋งค๋„ˆํ‰๊ฐ€ ๋ฉ”์‹œ์ง€์— timestamp ์ถ”๊ฐ€ ๋ฐ ์Šค์ผ€์ค„๋Ÿฌ ์‹คํ–‰ ๊ฐ„๊ฒฉ ๋ณ€๊ฒฝ
  • Loading branch information
Eunjin3395 authored Oct 13, 2024
2 parents b0ba91b + 8e97adf commit 4f081da
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 4f081da

Please sign in to comment.