Skip to content

Commit 696a58c

Browse files
committed
refactor: 버스 도착 정보 json 변환
1 parent 0e765d1 commit 696a58c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/java/com/example/busnotice/domain/fcmToken/FCMService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.example.busnotice.global.code.ErrorCode;
1111
import com.example.busnotice.global.code.StatusCode;
1212
import com.example.busnotice.global.exception.UserException;
13+
import com.fasterxml.jackson.core.JsonProcessingException;
14+
import com.fasterxml.jackson.databind.ObjectMapper;
1315
import com.google.firebase.messaging.FirebaseMessaging;
1416
import com.google.firebase.messaging.FirebaseMessagingException;
1517
import com.google.firebase.messaging.Message;
@@ -34,7 +36,7 @@ public class FCMService {
3436
private final UserRepository userRepository;
3537
private final ScheduleService scheduleService;
3638
private final ScheduleRepository scheduleRepository;
37-
39+
ObjectMapper objectMapper = new ObjectMapper(); // JSON 변환기
3840
@Transactional
3941
public void createFCMToken(Long userId, CreateFCMTokenRequest createFCMTokenRequest) {
4042
User user = userRepository.findById(userId).orElseThrow(
@@ -54,7 +56,7 @@ public void createFCMToken(Long userId, CreateFCMTokenRequest createFCMTokenRequ
5456

5557
@Scheduled(fixedRate = 60000) // 1분(60,000ms)마다 실행
5658
@Transactional(readOnly = true) // 트랜잭션 적용
57-
public void sendNotification() throws UnsupportedEncodingException {
59+
public void sendNotification() throws UnsupportedEncodingException, JsonProcessingException {
5860
List<FCMToken> allTokens = fcmRepository.findAll();
5961
List<UserNotificationData> notifications = new ArrayList<>();
6062

@@ -109,7 +111,7 @@ public void sendNotification() throws UnsupportedEncodingException {
109111
.setToken(notification.token())
110112
.putData("scheduleName", notification.scheduleName())
111113
.putData("days", notification.days().toString())
112-
.putData("busStopInfos", notification.busStopInfos().toString())
114+
.putData("busStopInfos", objectMapper.writeValueAsString(notification.busStopInfos()))
113115
.build();
114116

115117
try {

0 commit comments

Comments
 (0)