diff --git a/src/main/java/depth/mvp/thinkerbell/TestController.java b/src/main/java/depth/mvp/thinkerbell/TestController.java index 31c86b9..f210b73 100644 --- a/src/main/java/depth/mvp/thinkerbell/TestController.java +++ b/src/main/java/depth/mvp/thinkerbell/TestController.java @@ -1,5 +1,6 @@ package depth.mvp.thinkerbell; +import depth.mvp.thinkerbell.domain.user.service.AlarmService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -12,9 +13,16 @@ @CrossOrigin("*") public class TestController { + private final AlarmService alarmService; + @GetMapping("/test") public String test(){ return "배포 CD 테스트"; } + @GetMapping("/alarm-test") + public void testAlarm(String ssaid, String keyword){ + alarmService.updateNoticeAndMatchKeywordTest(ssaid, keyword); + } + } diff --git a/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java b/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java index d3d0ffe..2c31777 100644 --- a/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java +++ b/src/main/java/depth/mvp/thinkerbell/domain/user/service/AlarmService.java @@ -76,7 +76,11 @@ public void updateNoticeAndMatchKeyword(){ alarmRepository.save(alarm); - fcmService.sendFCMMessage(alarm, keyword.getKeyword()); + Map noticeDetails = getNoticeDetails(alarm.getNoticeType(), alarm.getNoticeID()); + + String url = (String) noticeDetails.get("url"); + + fcmService.sendFCMMessage(alarm, keyword.getKeyword(), url); } catch (Exception e) { throw new RuntimeException("유저 알림을 저장하거나, fcm 알림을 보내는 도중 오류가 발생했습니다.", e); } @@ -109,7 +113,7 @@ public void updateNoticeAndMatchKeyword(){ } } - public void updateNoticeAndMatchKeywordTest(){ + public void updateNoticeAndMatchKeywordTest(String ssaid, String key){ List crawlingNums; try { @@ -119,6 +123,9 @@ public void updateNoticeAndMatchKeywordTest(){ } for (CrawlingNum crawlingNum : crawlingNums) { + crawlingNum.setNoticeID(0L); + crawlingNumRepository.save(crawlingNum); + List allNoticesViews; try { @@ -136,7 +143,14 @@ public void updateNoticeAndMatchKeywordTest(){ try{ Alarm alarm = new Alarm(notice.getId(), notice.getTableName(), keyword.getUser(), notice.getTitle(), keyword.getKeyword()); - fcmService.sendFCMMessage(alarm, keyword.getKeyword()); + Map noticeDetails = getNoticeDetails(alarm.getNoticeType(), alarm.getNoticeID()); + + String url = (String) noticeDetails.get("url"); + + if (ssaid.equals(keyword.getUser().getSsaid()) && key.equals(keyword.getKeyword())){ + fcmService.sendFCMMessage(alarm, keyword.getKeyword(), url); + } + } catch (Exception e) { throw new RuntimeException("유저 알림을 저장하거나, fcm 알림을 보내는 도중 오류가 발생했습니다.", e); } diff --git a/src/main/java/depth/mvp/thinkerbell/domain/user/service/FCMService.java b/src/main/java/depth/mvp/thinkerbell/domain/user/service/FCMService.java index 77d7828..7c3304f 100644 --- a/src/main/java/depth/mvp/thinkerbell/domain/user/service/FCMService.java +++ b/src/main/java/depth/mvp/thinkerbell/domain/user/service/FCMService.java @@ -14,7 +14,7 @@ public class FCMService { private final CategoryService categoryService; - public void sendFCMMessage(Alarm alarm, String keyword) { + public void sendFCMMessage(Alarm alarm, String keyword, String url) { try{ String category = categoryService.getCategoryNameInKorean(alarm.getNoticeType()); String cutTitle = cutTitle(alarm.getTitle(), 30); @@ -25,7 +25,8 @@ public void sendFCMMessage(Alarm alarm, String keyword) { Message message = Message.builder() .putData("title", "띵커벨") .putData("body", messageBody) - .putData("notification_id", UUID.randomUUID().toString()) // 고유한 ID + .putData("notification_id", UUID.randomUUID().toString())// 고유한 ID + .putData("url", url) .setToken(alarm.getUser().getFcmToken()) .build();