Skip to content

Commit

Permalink
Merge pull request #37 from wnehgus101/feature/alarm
Browse files Browse the repository at this point in the history
[FEATURE] ์•Œ๋ฆผ ํ…Œ์ŠคํŠธ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ ๋ฐ ์•Œ๋ฆผ์— url ์ถ”๊ฐ€ ์ œ๊ณต
  • Loading branch information
ibaesuyeon authored Aug 21, 2024
2 parents 077917e + 51c3bdb commit b8f4f97
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/main/java/depth/mvp/thinkerbell/TestController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public void updateNoticeAndMatchKeyword(){

alarmRepository.save(alarm);

fcmService.sendFCMMessage(alarm, keyword.getKeyword());
Map<String, Object> 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);
}
Expand Down Expand Up @@ -109,7 +113,7 @@ public void updateNoticeAndMatchKeyword(){
}
}

public void updateNoticeAndMatchKeywordTest(){
public void updateNoticeAndMatchKeywordTest(String ssaid, String key){
List<CrawlingNum> crawlingNums;

try {
Expand All @@ -119,6 +123,9 @@ public void updateNoticeAndMatchKeywordTest(){
}

for (CrawlingNum crawlingNum : crawlingNums) {
crawlingNum.setNoticeID(0L);
crawlingNumRepository.save(crawlingNum);

List<AllNoticesView> allNoticesViews;

try {
Expand All @@ -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<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit b8f4f97

Please sign in to comment.