Skip to content

Commit

Permalink
7/13 배포 작업 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc authored Jul 13, 2024
1 parent 1a8c424 commit c4d2a6c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/backend/itracker/alarm/service/AlarmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,7 +28,7 @@ class NotificationClient(
private val eventPublisher: ApplicationEventPublisher,
) : NotificationSender {

override fun sendPriceChangeNotification(
override fun reserveNotificationOfPriceChange(
priceChangeTemplate: PriceChangeNotificationInfo,
receiverPhoneNumbers: List<String>,
) {
Expand All @@ -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 {
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import backend.itracker.schedule.service.notification.dto.PriceChangeNotificatio

interface NotificationSender {

fun sendPriceChangeNotification(
fun reserveNotificationOfPriceChange(
priceChangeTemplate: PriceChangeNotificationInfo,
receiverPhoneNumbers: List<String>,
)
Expand Down

0 comments on commit c4d2a6c

Please sign in to comment.