Skip to content

Commit

Permalink
refactor: 아티클 이메일 전송시 전송 이벤트 기록하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Sep 21, 2024
1 parent 1c42574 commit bae112a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
)
}
}
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit bae112a

Please sign in to comment.