From ad090ecaadd370cc052dc5300168ab07f189f3d3 Mon Sep 17 00:00:00 2001 From: sookyung kang Date: Tue, 19 Mar 2024 14:39:37 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8:=20feat=20=EC=98=A4=EB=8A=98=EC=9D=98?= =?UTF-8?q?=20=EC=A7=88=EB=AC=B8=20daily=20notification=20#33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/th/plu/api/PluApiApplication.kt | 12 +++++++----- .../notification/ScheduledNotificationSender.kt | 16 ++++++++++++++++ .../dto/request/MessageSendRequest.kt | 6 ++++++ .../notification/PluNotificationApplication.kt | 10 ++++++---- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 plu-api/src/main/kotlin/com/th/plu/api/controller/notification/ScheduledNotificationSender.kt diff --git a/plu-api/src/main/kotlin/com/th/plu/api/PluApiApplication.kt b/plu-api/src/main/kotlin/com/th/plu/api/PluApiApplication.kt index 4ed30ce..8e1a651 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/PluApiApplication.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/PluApiApplication.kt @@ -5,15 +5,17 @@ import com.th.plu.domain.PluDomainRoot import com.th.plu.external.PluExternalRoot import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.scheduling.annotation.EnableScheduling +@EnableScheduling @SpringBootApplication(scanBasePackageClasses = [ - PluApiApplication::class, - PluDomainRoot::class, - PluCommonRoot::class, - PluExternalRoot::class + PluApiApplication::class, + PluDomainRoot::class, + PluCommonRoot::class, + PluExternalRoot::class ]) class PluApiApplication fun main(args: Array) { - runApplication(*args) + runApplication(*args) } diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/ScheduledNotificationSender.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/ScheduledNotificationSender.kt new file mode 100644 index 0000000..4da3ecb --- /dev/null +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/ScheduledNotificationSender.kt @@ -0,0 +1,16 @@ +package com.th.plu.api.controller.notification + +import com.th.plu.api.controller.notification.dto.request.MessageSendRequest +import com.th.plu.api.service.notification.NotificationService +import com.th.plu.common.Slf4JKotlinLogging.log +import org.springframework.scheduling.annotation.Scheduled +import org.springframework.stereotype.Component + +@Component +class ScheduledNotificationSender(private val notificationService: NotificationService) { + @Scheduled(cron = "0 0 22 * * ?") + fun sendDailyNotification() { + notificationService.sendMessageToAllMember(MessageSendRequest.DAILY_QUESTION_MESSAGE()) + log.info { "오늘의 질문 알림을 보냈습니다." } + } +} \ No newline at end of file diff --git a/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/dto/request/MessageSendRequest.kt b/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/dto/request/MessageSendRequest.kt index 9b9accb..8366c27 100644 --- a/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/dto/request/MessageSendRequest.kt +++ b/plu-api/src/main/kotlin/com/th/plu/api/controller/notification/dto/request/MessageSendRequest.kt @@ -1,4 +1,10 @@ package com.th.plu.api.controller.notification.dto.request data class MessageSendRequest(var title: String, var body: String) { + companion object { + fun DAILY_QUESTION_MESSAGE() = MessageSendRequest( + title = "오늘의 질문 알림", + body = "오늘의 질문에 답할 시간입니다." + ) + } } diff --git a/plu-notification/src/main/kotlin/com/th/plu/notification/PluNotificationApplication.kt b/plu-notification/src/main/kotlin/com/th/plu/notification/PluNotificationApplication.kt index 152b28c..7940522 100644 --- a/plu-notification/src/main/kotlin/com/th/plu/notification/PluNotificationApplication.kt +++ b/plu-notification/src/main/kotlin/com/th/plu/notification/PluNotificationApplication.kt @@ -4,14 +4,16 @@ import com.th.plu.common.PluCommonRoot import com.th.plu.external.PluExternalRoot import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.scheduling.annotation.EnableScheduling +@EnableScheduling @SpringBootApplication(scanBasePackageClasses = [ - PluNotificationApplication::class, - PluCommonRoot::class, - PluExternalRoot::class + PluNotificationApplication::class, + PluCommonRoot::class, + PluExternalRoot::class ]) class PluNotificationApplication fun main(args: Array) { - runApplication(*args) + runApplication(*args) }