Skip to content

Commit

Permalink
Fcm 데일리, 리마인드 메서드 통일 (#208)
Browse files Browse the repository at this point in the history
* fix: 알림메시지 boolean으로 분리 및 sendDaily메서드 null 에러수정

* fix: test코드 수정

* fix: Daily, reminder 메세드 통일

* fix: API테스트용 코드 삭제
  • Loading branch information
dbscks97 authored Aug 24, 2024
1 parent 861a7ed commit 3a8eead
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -41,7 +42,8 @@ public ResponseEntity<Void> pushMessageToAll(
Notification notification =
FcmNotificationUtil.buildNotification(
fcmSendRequest.title(), fcmSendRequest.body());
fcmService.sendMulticastMessageToAll(notification);
List<String> tokens = fcmTokenService.getAllTokens();
fcmService.sendMulticastMessage(notification, tokens);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void sendDailyNotification() {
FcmNotificationConstants notificationConstants = FcmNotificationConstants.MISSION_START;
String title = notificationConstants.getTitle();
String message = notificationConstants.getMessage();

List<String> tokens = fcmTokenService.getAllTokens();

fcmNotificationService.sendAndNotifications(title, message, tokens);

log.info("모든 사용자에게 정규 알림 전송 및 저장 완료");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ public class FcmService {
private final FcmTokenService fcmTokenService;

@Transactional(readOnly = true)
public void sendMulticastMessageToAll(Notification notification) {
List<String> tokens = fcmTokenService.getAllTokens();
int totalTokens = tokens.size();

for (int i = 0; i < totalTokens; i += BATCH_SIZE) {
List<String> batchTokens = tokens.subList(i, Math.min(i + BATCH_SIZE, totalTokens));
MulticastMessage message = buildMulticastMessage(notification, batchTokens);
sendMessage(message, batchTokens);
}

log.info("전체 메세지를 일괄 전송했습니다. 총 메세지 수: {}", totalTokens);
}

@Transactional
public void sendMulticastMessage(Notification notification, List<String> tokens) {
int totalTokens = tokens.size();

Expand All @@ -42,7 +28,7 @@ public void sendMulticastMessage(Notification notification, List<String> tokens)
sendMessage(message, batchTokens);
}

log.info("리마인드 메세지를 일괄 전송했습니다. 총 메세지 수: {}", totalTokens);
log.info("전체 메세지를 일괄 전송했습니다. 총 메세지 수: {}", totalTokens);
}

private MulticastMessage buildMulticastMessage(Notification notification, List<String> tokens) {
Expand Down

0 comments on commit 3a8eead

Please sign in to comment.