Skip to content

Commit

Permalink
fix: in의 잘못된 사용으로 마지막 학습지를 받지 않은 구독자들도 구독을 해지하는 문제 해결 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 authored Jul 14, 2024
1 parent 1d3fbd4 commit 3937837
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ data class ArticleContent(
val writerLink: URL
)

data class ReceiveLastDayMember(
val memberId: Long,
val targetWorkBookId: Long
)

fun List<ArticleContent>.peek(articleId: Long): ArticleContent {
return this.find {
it.id == articleId
Expand Down Expand Up @@ -191,9 +196,9 @@ class WorkBookSubscriberWriter(
}.filter {
(it.progress.toInt() + 1) == lastDayCol[it.targetWorkBookId]
}.map {
it.memberId
ReceiveLastDayMember(it.memberId, it.targetWorkBookId)
}.filter {
memberSuccessRecords[it] == true
memberSuccessRecords[it.memberId] == true
}

val successMemberIds = memberSuccessRecords.filter { it.value }.keys
Expand All @@ -205,12 +210,15 @@ class WorkBookSubscriberWriter(
.execute()

/** 마지막 학습지를 받은 구독자들은 구독을 해지한다.*/
dslContext.update(subscriptionT)
.set(subscriptionT.DELETED_AT, LocalDateTime.now())
.set(subscriptionT.UNSUBS_OPINION, "receive.all")
.where(subscriptionT.MEMBER_ID.`in`(receiveLastDayMembers))
.and(subscriptionT.TARGET_WORKBOOK_ID.`in`(targetWorkBookIds))
.execute()
// todo refactoring to batch update
for (receiveLastDayMember in receiveLastDayMembers) {
dslContext.update(subscriptionT)
.set(subscriptionT.DELETED_AT, LocalDateTime.now())
.set(subscriptionT.UNSUBS_OPINION, "receive.all")
.where(subscriptionT.MEMBER_ID.eq(receiveLastDayMember.memberId))
.and(subscriptionT.TARGET_WORKBOOK_ID.eq(receiveLastDayMember.targetWorkBookId))
.execute()
}

return if (failRecords.isNotEmpty()) {
mapOf("records" to memberSuccessRecords, "fail" to failRecords)
Expand Down

0 comments on commit 3937837

Please sign in to comment.