Skip to content
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

Merged
merged 20 commits into from
Aug 27, 2024

Conversation

belljun3395
Copy link
Collaborator

🎫 연관 이슈

resolved: #360

💁‍♂️ PR 내용

  • 구독과 동시에 아티클 전송할 수 있도록 수정

🙏 작업

  • 구독 이벤트 내용 수정
    • as-is: 워크북 ID, to-be: 워크북 ID 멤버 ID 날짜
  • 이벤트 리스너 구현 통일
  • 트렌젝션이 완료된 이후 동작하는 리스너 구현 : 이메일 전송 성공/실패 여부를 UC 트랜잭션과 분리하기 위해서

🙈 PR 참고 사항

📸 스크린샷

🤖 테스트 체크리스트

  • 체크 미완료
  • 체크 완료

@belljun3395 belljun3395 requested a review from hun-ca as a code owner August 27, 2024 00:48
@github-actions github-actions bot added the refactor 기존 기능에 대해 개선할 때 사용됩니다. label Aug 27, 2024
Comment on lines +56 to 68
/**
* 구독 이벤트 발행
* @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
)
)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구독 이벤트를 발행합니다.

Comment on lines -22 to -37
@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)
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제된 설정은 Handler에서 설정하도록 수정하였습니다.
-> Handler 마다 별도의 설정이 가능하는 장점이 있다고 생각했어요

Comment on lines +16 to +17
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMPLETION)
@Transactional(propagation = Propagation.REQUIRES_NEW)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UC의 트랜잭션이 종료된 이후 새로운 트랜잭션을 생성하여 이벤트를 처리합니다.

Comment on lines +60 to +77
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)
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메일이 전송되면 진행을 +1 하는 로직입니다.

만약 전송된 날이 마지막 날이라면 구독을 종료합니다.

@belljun3395 belljun3395 merged commit 0eb26b2 into dev Aug 27, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 기존 기능에 대해 개선할 때 사용됩니다.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

구독과 동시에 아티클 전송할 수 있도록 수정
1 participant