From d61ff924253ad4f05798dfdcf91193d24fbd3607 Mon Sep 17 00:00:00 2001 From: WhitePiano Date: Thu, 1 Feb 2024 20:53:39 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Events=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=BB=AC=EB=9E=99=EC=85=98=20=EB=9E=98=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plantory/event/notification/WaterCycleEventListener.kt | 4 ++-- .../gdsc/plantory/event/notification/WaterCycleEvents.kt | 5 +++++ .../kotlin/gdsc/plantory/plant/service/ReminderService.kt | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEvents.kt diff --git a/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEventListener.kt b/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEventListener.kt index 5d7d617..e16fe66 100644 --- a/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEventListener.kt +++ b/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEventListener.kt @@ -24,8 +24,8 @@ class WaterCycleEventListener( @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) @Async - fun sendFcmNotification(events: List) { - val messages: List = createMessages(events, FCMChannel.WATER_ALERT.name) + fun sendFcmNotification(events: WaterCycleEvents) { + val messages: List = createMessages(events.plantsNeedWateredToday, FCMChannel.WATER_ALERT.name) try { firebaseMessaging.sendEach(messages) diff --git a/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEvents.kt b/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEvents.kt new file mode 100644 index 0000000..0aed489 --- /dev/null +++ b/src/main/kotlin/gdsc/plantory/event/notification/WaterCycleEvents.kt @@ -0,0 +1,5 @@ +package gdsc.plantory.event.notification + +data class WaterCycleEvents( + val plantsNeedWateredToday: List +) \ No newline at end of file diff --git a/src/main/kotlin/gdsc/plantory/plant/service/ReminderService.kt b/src/main/kotlin/gdsc/plantory/plant/service/ReminderService.kt index 0117e4c..2288850 100644 --- a/src/main/kotlin/gdsc/plantory/plant/service/ReminderService.kt +++ b/src/main/kotlin/gdsc/plantory/plant/service/ReminderService.kt @@ -2,6 +2,7 @@ package gdsc.plantory.plant.service import gdsc.plantory.event.Events import gdsc.plantory.event.notification.WaterCycleEvent +import gdsc.plantory.event.notification.WaterCycleEvents import gdsc.plantory.plant.domain.CompanionPlantRepository import gdsc.plantory.plant.presentation.dto.CompanionPlantWaterCycleDto import org.springframework.scheduling.annotation.Scheduled @@ -18,7 +19,7 @@ class ReminderService( @Scheduled(cron = "0 0 8 * * *") fun sendWaterNotification() { val companionPlants = companionPlantRepository.findAllByNextWaterDate(LocalDate.now()) - val events: List = buildWaterCycleEvents(companionPlants) + val events = WaterCycleEvents(buildWaterCycleEvents(companionPlants)) Events.raise(events) }