From 51d148ff6a8b099705c84a37c8239e804ed01903 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 21 Sep 2024 21:48:10 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=95=84=ED=8B=B0=ED=81=B4=20?= =?UTF-8?q?=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=A0=84=EC=86=A1=EC=8B=9C=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SendWorkbookArticleAsyncHandler.kt | 20 +++++++++++---- .../service/SubscriptionEmailService.kt | 4 +-- .../service/SubscriptionLogService.kt | 25 +++++++++++++++++++ .../service/dto/InsertSendEventDto.kt | 8 ++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionLogService.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/subscription/service/dto/InsertSendEventDto.kt diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/handler/SendWorkbookArticleAsyncHandler.kt b/api/src/main/kotlin/com/few/api/domain/subscription/handler/SendWorkbookArticleAsyncHandler.kt index 9bf3d27c..99bf96e1 100644 --- a/api/src/main/kotlin/com/few/api/domain/subscription/handler/SendWorkbookArticleAsyncHandler.kt +++ b/api/src/main/kotlin/com/few/api/domain/subscription/handler/SendWorkbookArticleAsyncHandler.kt @@ -3,16 +3,14 @@ package com.few.api.domain.subscription.handler import com.few.api.config.DatabaseAccessThreadPoolConfig.Companion.DATABASE_ACCESS_POOL import com.few.api.domain.common.lock.LockFor import com.few.api.domain.common.lock.LockIdentifier -import com.few.api.domain.subscription.service.SubscriptionArticleService -import com.few.api.domain.subscription.service.SubscriptionMemberService -import com.few.api.domain.subscription.service.SubscriptionEmailService -import com.few.api.domain.subscription.service.SubscriptionWorkbookService +import com.few.api.domain.subscription.service.* import com.few.api.domain.subscription.service.dto.* import com.few.api.exception.common.NotFoundException import com.few.api.repo.dao.subscription.SubscriptionDao import com.few.api.repo.dao.subscription.command.UpdateArticleProgressCommand import com.few.api.repo.dao.subscription.command.UpdateLastArticleProgressCommand import com.few.api.repo.dao.subscription.query.SelectSubscriptionQuery +import com.few.api.web.support.SendType import com.few.data.common.code.CategoryType import com.few.email.service.article.dto.Content import io.github.oshai.kotlinlogging.KotlinLogging @@ -27,6 +25,7 @@ class SendWorkbookArticleAsyncHandler( private val memberService: SubscriptionMemberService, private val articleService: SubscriptionArticleService, private val workbookService: SubscriptionWorkbookService, + private val subscriptionLogService: SubscriptionLogService, private val subscriptionDao: SubscriptionDao, private val emailService: SubscriptionEmailService, ) { @@ -80,8 +79,19 @@ class SendWorkbookArticleAsyncHandler( ) ) - runCatching { emailService.sendArticleEmail(sendArticleInDto) } + runCatching { + emailService.sendArticleEmail(sendArticleInDto) + } .onSuccess { + subscriptionLogService.insertSendEvent( + InsertSendEventDto( + memberId = memberId, + articleId = article.id, + messageId = it, + sendType = SendType.AWSSES.code + ) + ) + val lastDayArticleId = workbookService.readWorkbookLastArticleId( ReadWorkbookLastArticleIdInDto( diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionEmailService.kt b/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionEmailService.kt index 2865ed18..311ef73a 100644 --- a/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionEmailService.kt +++ b/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionEmailService.kt @@ -15,8 +15,8 @@ class SubscriptionEmailService( private const val ARTICLE_TEMPLATE = "article" } - fun sendArticleEmail(dto: SendArticleInDto) { - sendArticleEmailService.send( + fun sendArticleEmail(dto: SendArticleInDto): String { + return sendArticleEmailService.send( SendArticleEmailArgs( dto.toEmail, ARTICLE_SUBJECT_TEMPLATE.format( diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionLogService.kt b/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionLogService.kt new file mode 100644 index 00000000..858546fc --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionLogService.kt @@ -0,0 +1,25 @@ +package com.few.api.domain.subscription.service + +import com.few.api.domain.subscription.service.dto.InsertSendEventDto +import com.few.api.repo.dao.log.SendArticleEventHistoryDao +import com.few.api.repo.dao.log.command.InsertEventCommand +import com.few.api.web.support.EmailLogEventType +import org.springframework.stereotype.Service + +@Service +class SubscriptionLogService( + private val sendArticleEventHistoryDao: SendArticleEventHistoryDao, +) { + + fun insertSendEvent(dto: InsertSendEventDto) { + sendArticleEventHistoryDao.insertEvent( + InsertEventCommand( + memberId = dto.memberId, + articleId = dto.articleId, + messageId = dto.messageId, + eventType = EmailLogEventType.SEND.code, + sendType = dto.sendType + ) + ) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/service/dto/InsertSendEventDto.kt b/api/src/main/kotlin/com/few/api/domain/subscription/service/dto/InsertSendEventDto.kt new file mode 100644 index 00000000..ec773607 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/subscription/service/dto/InsertSendEventDto.kt @@ -0,0 +1,8 @@ +package com.few.api.domain.subscription.service.dto + +data class InsertSendEventDto( + val memberId: Long, + val articleId: Long, + val messageId: String, + val sendType: Byte, +) \ No newline at end of file