-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor/#360] 구독과 동시에 아티클 전송할 수 있도록 수정 #364
Conversation
/** | ||
* 구독 이벤트 발행 | ||
* @see com.few.api.domain.subscription.event.WorkbookSubscriptionEventListener | ||
* @see com.few.api.domain.subscription.event.WorkbookSubscriptionAfterCompletionEventListener | ||
*/ | ||
applicationEventPublisher.publishEvent( | ||
WorkbookSubscriptionEvent( | ||
workbookId = subTargetWorkbookId, | ||
memberId = memberId, | ||
articleDayCol = subscriptionStatus?.day ?: 1 | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구독 이벤트를 발행합니다.
@Async(value = DISCORD_HOOK_EVENT_POOL) | ||
@EventListener | ||
fun handleWorkbookSubscriptionEvent(event: WorkbookSubscriptionEvent) { | ||
val title = ReadWorkbookTitleInDto(event.workbookId).let { dto -> | ||
workbookService.readWorkbookTitle(dto)?.workbookTitle | ||
?: throw NotFoundException("workbook.notfound.id") | ||
} | ||
subscriptionDao.countAllSubscriptionStatus().let { record -> | ||
WorkbookSubscriptionArgs( | ||
totalSubscriptions = record.totalSubscriptions, | ||
activeSubscriptions = record.activeSubscriptions, | ||
workbookTitle = title | ||
).let { args -> | ||
subscriptionClient.announceWorkbookSubscription(args) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
삭제된 설정은 Handler에서 설정하도록 수정하였습니다.
-> Handler 마다 별도의 설정이 가능하는 장점이 있다고 생각했어요
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION) | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UC의 트랜잭션이 종료된 이후 새로운 트랜잭션을 생성하여 이벤트를 처리합니다.
runCatching { emailService.sendArticleEmail(it) } | ||
.onSuccess { | ||
val lastDayArticleId = ReadWorkbookLastArticleIdInDto( | ||
workbookId | ||
).let { | ||
workbookService.readWorkbookLastArticleId(it) | ||
}?.lastArticleId ?: throw NotFoundException("workbook.notfound.id") | ||
|
||
if (article.id == lastDayArticleId) { | ||
UpdateArticleProgressCommand(workbookId, memberId).let { | ||
subscriptionDao.updateArticleProgress(it) | ||
} | ||
} else { | ||
UpdateLastArticleProgressCommand(workbookId, memberId).let { | ||
subscriptionDao.updateLastArticleProgress(it) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메일이 전송되면 진행을 +1 하는 로직입니다.
만약 전송된 날이 마지막 날이라면 구독을 종료합니다.
🎫 연관 이슈
resolved: #360
💁♂️ PR 내용
🙏 작업
🙈 PR 참고 사항
📸 스크린샷
🤖 테스트 체크리스트