Skip to content

Commit

Permalink
refactor: 구독정보 조회 쿼리 분리 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Aug 8, 2024
1 parent 4210d4b commit b0374c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import com.few.api.domain.subscription.usecase.dto.BrowseSubscribeWorkbooksUseCa
import com.few.api.domain.subscription.usecase.dto.SubscribeWorkbookDetail
import com.few.api.repo.dao.subscription.SubscriptionDao
import com.few.api.repo.dao.subscription.query.CountAllWorkbooksSubscription
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscription
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookInActiveSubscription
import com.few.api.web.support.WorkBookStatus
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
Expand All @@ -21,11 +22,18 @@ class BrowseSubscribeWorkbooksUseCase(
) {
@Transactional
fun execute(useCaseIn: BrowseSubscribeWorkbooksUseCaseIn): BrowseSubscribeWorkbooksUseCaseOut {
val subscriptionRecords =
SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery(useCaseIn.memberId).let {
subscriptionDao.selectAllWorkbookSubscriptionStatus(it)
val inActiveSubscriptionRecords =
SelectAllMemberWorkbookInActiveSubscription(useCaseIn.memberId).let {
subscriptionDao.selectAllInActiveWorkbookSubscriptionStatus(it)
}

val activeSubscriptionRecords =
SelectAllMemberWorkbookActiveSubscription(useCaseIn.memberId).let {
subscriptionDao.selectAllActiveWorkbookSubscriptionStatus(it)
}

val subscriptionRecords = inActiveSubscriptionRecords + activeSubscriptionRecords

/**
* key: workbookId
* value: workbook의 currentDay에 해당하는 articleId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.few.api.domain.workbook.service
import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksInDto
import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksOutDto
import com.few.api.repo.dao.subscription.SubscriptionDao
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscription
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookInActiveSubscription
import org.springframework.stereotype.Service

@Service
Expand All @@ -12,14 +13,24 @@ class WorkbookSubscribeService(
) {

fun browseMemberSubscribeWorkbooks(dto: BrowseMemberSubscribeWorkbooksInDto): List<BrowseMemberSubscribeWorkbooksOutDto> {
return SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery(dto.memberId).let { it ->
subscriptionDao.selectAllWorkbookSubscriptionStatus(it).map {
BrowseMemberSubscribeWorkbooksOutDto(
workbookId = it.workbookId,
isActiveSub = it.isActiveSub,
currentDay = it.currentDay
)
val inActiveSubscriptionRecords =
SelectAllMemberWorkbookInActiveSubscription(dto.memberId).let {
subscriptionDao.selectAllInActiveWorkbookSubscriptionStatus(it)
}

val activeSubscriptionRecords =
SelectAllMemberWorkbookActiveSubscription(dto.memberId).let {
subscriptionDao.selectAllActiveWorkbookSubscriptionStatus(it)
}

val subscriptionRecords = inActiveSubscriptionRecords + activeSubscriptionRecords

return subscriptionRecords.map {
BrowseMemberSubscribeWorkbooksOutDto(
workbookId = it.workbookId,
isActiveSub = it.isActiveSub,
currentDay = it.currentDay
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ class BrowseSubscribeWorkbooksUseCaseTest : BehaviorSpec({

given("사용자 구독 정보 조회 요청이 온 상황에서") {
`when`("사용자의 구독 정보가 있는 경우") {
every { subscriptionDao.selectAllWorkbookSubscriptionStatus(any()) } returns listOf(
every { subscriptionDao.selectAllInActiveWorkbookSubscriptionStatus(any()) } returns listOf(
MemberWorkbookSubscriptionStatusRecord(
workbookId = 1L,
isActiveSub = true,
isActiveSub = false,
currentDay = 1,
totalDay = 3
),
)
)

every { subscriptionDao.selectAllActiveWorkbookSubscriptionStatus(any()) } returns listOf(
MemberWorkbookSubscriptionStatusRecord(
workbookId = 2L,
isActiveSub = true,
Expand All @@ -58,7 +61,8 @@ class BrowseSubscribeWorkbooksUseCaseTest : BehaviorSpec({
val useCaseIn = BrowseSubscribeWorkbooksUseCaseIn(memberId = 1L)
useCase.execute(useCaseIn)

verify(exactly = 1) { subscriptionDao.selectAllWorkbookSubscriptionStatus(any()) }
verify(exactly = 1) { subscriptionDao.selectAllInActiveWorkbookSubscriptionStatus(any()) }
verify(exactly = 1) { subscriptionDao.selectAllActiveWorkbookSubscriptionStatus(any()) }
verify(exactly = 1) { subscriptionDao.countAllWorkbookSubscription(any()) }
verify(exactly = 2) { objectMapper.writeValueAsString(any()) }
}
Expand Down

0 comments on commit b0374c0

Please sign in to comment.