diff --git a/src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt b/src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt index 74dd7a8..d16fe8b 100644 --- a/src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt +++ b/src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt @@ -3,6 +3,7 @@ package backend.itracker.alarm.service import backend.itracker.alarm.infra.slack.Color import backend.itracker.alarm.infra.slack.SlackClient import backend.itracker.alarm.service.event.FailedNotificationEvent +import backend.itracker.alarm.service.event.SuccessReservationOfNotificationEvent import backend.itracker.crawl.service.CrawlResultService import backend.itracker.schedule.service.event.CrawlEndEvent import org.springframework.context.event.EventListener @@ -44,4 +45,22 @@ class AlarmService ( event.getMessages() ) } + + @EventListener(SuccessReservationOfNotificationEvent::class) + fun alarmNotificationSuccessEvent(event: SuccessReservationOfNotificationEvent) { + slackClient.sendNotification( + """ + |*[ 알림 예약 성공 ]* + |*예약 시간* : ${event.reservationTime()} + """.trimMargin(), + Color.GREEN, + listOf( + """ + |*전송한 메세지 수* : ${event.successMessageCount()} + |*남은 포인트* : ${event.point()} + |*잔액* : ${event.balance()} + """.trimIndent() + ) + ) + } } diff --git a/src/main/kotlin/backend/itracker/alarm/service/event/SuccessReservationOfNotificationEvent.kt b/src/main/kotlin/backend/itracker/alarm/service/event/SuccessReservationOfNotificationEvent.kt new file mode 100644 index 0000000..c34bb68 --- /dev/null +++ b/src/main/kotlin/backend/itracker/alarm/service/event/SuccessReservationOfNotificationEvent.kt @@ -0,0 +1,15 @@ +package backend.itracker.alarm.service.event + +import java.time.LocalDateTime + + +interface SuccessReservationOfNotificationEvent { + + fun reservationTime(): LocalDateTime + + fun successMessageCount(): Int + + fun point(): Float + + fun balance(): Float +} diff --git a/src/main/kotlin/backend/itracker/schedule/infra/notification/event/MessageReservationSuccessEvent.kt b/src/main/kotlin/backend/itracker/schedule/infra/notification/event/MessageReservationSuccessEvent.kt new file mode 100644 index 0000000..5494fe1 --- /dev/null +++ b/src/main/kotlin/backend/itracker/schedule/infra/notification/event/MessageReservationSuccessEvent.kt @@ -0,0 +1,28 @@ +package backend.itracker.schedule.infra.notification.event + +import backend.itracker.alarm.service.event.SuccessReservationOfNotificationEvent +import java.time.LocalDateTime + +data class MessageReservationSuccessEvent( + val reservationTime: LocalDateTime, + val successMessageCount: Int, + val point: Float, + val balance: Float, +) : SuccessReservationOfNotificationEvent { + + override fun reservationTime(): LocalDateTime { + return reservationTime + } + + override fun successMessageCount(): Int { + return successMessageCount + } + + override fun point(): Float { + return point + } + + override fun balance(): Float { + return balance + } +} diff --git a/src/main/kotlin/backend/itracker/schedule/infra/notification/solapi/NotificationClient.kt b/src/main/kotlin/backend/itracker/schedule/infra/notification/solapi/NotificationClient.kt index 8e8c2c7..28a2823 100644 --- a/src/main/kotlin/backend/itracker/schedule/infra/notification/solapi/NotificationClient.kt +++ b/src/main/kotlin/backend/itracker/schedule/infra/notification/solapi/NotificationClient.kt @@ -1,5 +1,6 @@ package backend.itracker.schedule.infra.notification.solapi +import backend.itracker.schedule.infra.notification.event.MessageReservationSuccessEvent import backend.itracker.schedule.infra.notification.event.MessageSendFailEvent import backend.itracker.schedule.infra.notification.solapi.config.NurigoKakaoChannelConfig import backend.itracker.schedule.service.notification.NotificationSender @@ -27,7 +28,7 @@ class NotificationClient( private val eventPublisher: ApplicationEventPublisher, ) : NotificationSender { - override fun sendPriceChangeNotification( + override fun reserveNotificationOfPriceChange( priceChangeTemplate: PriceChangeNotificationInfo, receiverPhoneNumbers: List, ) { @@ -51,6 +52,15 @@ class NotificationClient( try { messageService.send(messages, scheduledDateTime) + val balance = messageService.getBalance() + eventPublisher.publishEvent( + MessageReservationSuccessEvent( + reservationTime = reservationTime!!, + point = balance.point!!, + balance = balance.balance!!, + successMessageCount = messages.size + ) + ) } catch (exception: NurigoMessageNotReceivedException) { logger.error { """ diff --git a/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSchedulerService.kt b/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSchedulerService.kt index 8101dc2..f24c4f7 100644 --- a/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSchedulerService.kt +++ b/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSchedulerService.kt @@ -24,7 +24,7 @@ class NotificationSchedulerService( productCategoryMap.forEach { (product, members) -> val priceChangeNotificationInfo = notificationComposite.getPriceChangeNotificationInfo(product) val receiverPhoneNumbers = members.mapNotNull { it.phoneNumber } - notificationSender.sendPriceChangeNotification(priceChangeNotificationInfo, receiverPhoneNumbers) + notificationSender.reserveNotificationOfPriceChange(priceChangeNotificationInfo, receiverPhoneNumbers) } } } diff --git a/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSender.kt b/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSender.kt index 78f76ff..0526104 100644 --- a/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSender.kt +++ b/src/main/kotlin/backend/itracker/schedule/service/notification/NotificationSender.kt @@ -4,7 +4,7 @@ import backend.itracker.schedule.service.notification.dto.PriceChangeNotificatio interface NotificationSender { - fun sendPriceChangeNotification( + fun reserveNotificationOfPriceChange( priceChangeTemplate: PriceChangeNotificationInfo, receiverPhoneNumbers: List, )