diff --git a/src/main/java/org/terning/TerningApplication.java b/src/main/java/org/terning/TerningApplication.java index 0a63881..d5014da 100644 --- a/src/main/java/org/terning/TerningApplication.java +++ b/src/main/java/org/terning/TerningApplication.java @@ -1,15 +1,15 @@ package org.terning; -import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.scheduling.annotation.EnableScheduling; import org.terning.user.config.FcmProperties; @SpringBootApplication -@EnableBatchProcessing @EnableJpaAuditing +@EnableScheduling @EnableConfigurationProperties(FcmProperties.class) public class TerningApplication { diff --git a/src/main/java/org/terning/config/RestTemplateConfig.java b/src/main/java/org/terning/config/RestTemplateConfig.java new file mode 100644 index 0000000..70913a9 --- /dev/null +++ b/src/main/java/org/terning/config/RestTemplateConfig.java @@ -0,0 +1,14 @@ +package org.terning.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestTemplateConfig { + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/src/main/java/org/terning/fcm/application/FcmPushScheduler.java b/src/main/java/org/terning/fcm/application/FcmPushScheduler.java new file mode 100644 index 0000000..7bbd5df --- /dev/null +++ b/src/main/java/org/terning/fcm/application/FcmPushScheduler.java @@ -0,0 +1,91 @@ +package org.terning.fcm.application; + +import java.util.HashMap; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +@RequiredArgsConstructor +@Slf4j +public class FcmPushScheduler { + + private final RestTemplate restTemplate; + + private static final String BASE_URL = "http://13.209.210.3/api/v1"; + + private void callPost(String path) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(headers); + + String url = BASE_URL + path; + try { + restTemplate.postForEntity(url, entity, String.class); + log.info("POST 요청 성공: {}", url); + } catch (Exception e) { + log.error("POST 요청 실패: {}", url, e); + } + } + + private void callPost(String path, String template) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + Map bM = new HashMap<>(); + bM.put("template", template); + + HttpEntity> entity = new HttpEntity<>(bM, headers); + String url = BASE_URL + path; + + try { + restTemplate.postForEntity(url, entity, String.class); + log.info("POST 요청 성공: {}", url); + } catch (Exception e) { + log.error("POST 요청 실패: {}", url, e); + } + } + + private void callGet(String path) { + String url = BASE_URL + path; + try { + restTemplate.getForEntity(url, String.class); + log.info("GET 요청 성공: {}", url); + } catch (Exception e) { + log.error("GET 요청 실패: {}", url, e); + } + } + + // 1. 매주 월/수 16:58 스크랩 동기화 + @Scheduled(cron = "0 58 16 ? * MON,WED", zone = "Asia/Seoul") + public void syncScraps() { + callGet("/external/scraps/sync"); + } + + // 1-2. 매주 월/수 17:00 관심공고 알림 생성 + 전송 + @Scheduled(cron = "0 0 17 ? * MON,WED", zone = "Asia/Seoul") + public void sendInterestedAnnouncementReminder() { + callPost("/notification/create", "INTERESTED_ANNOUNCEMENT_REMINDER"); + callPost("/push-notifications/send-all"); + } + + // 2. 매주 목/토 13:00 최근 공고 알림 생성 + 전송 + @Scheduled(cron = "0 0 13 ? * THU,SAT", zone = "Asia/Seoul") + public void sendRecentlyPostedInternshipRecommendation() { + callPost("/notification/create", "RECENTLY_POSTED_INTERNSHIP_RECOMMENDATION"); + callPost("/push-notifications/send-all"); + } + + // 3. 매주 일요일 21:00 인기 공고 알림 생성 + 전송 + @Scheduled(cron = "0 0 21 ? * SUN", zone = "Asia/Seoul") + public void sendTrendingInternshipAlert() { + callPost("/notification/create", "TRENDING_INTERNSHIP_ALERT"); + callPost("/push-notifications/send-all"); + } +} diff --git a/src/test/java/org/terning/TerningApplicationTests.java b/src/test/java/org/terning/TerningApplicationTests.java deleted file mode 100644 index 1b526aa..0000000 --- a/src/test/java/org/terning/TerningApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.terning; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class TerningApplicationTests { - - @Test - void contextLoads() { - } - -}