diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/SubscriptionDao.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/SubscriptionDao.kt index 636dea158..729a5d156 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/SubscriptionDao.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/SubscriptionDao.kt @@ -7,7 +7,7 @@ import com.few.api.repo.dao.subscription.query.CountAllWorkbooksSubscription import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery import com.few.api.repo.dao.subscription.record.WorkbookSubscriptionStatus import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery -import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery +import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery import com.few.api.repo.dao.subscription.record.CountAllSubscriptionStatusRecord import com.few.api.repo.dao.subscription.record.MemberWorkbookSubscriptionStatusRecord import jooq.jooq_dsl.Tables.MAPPING_WORKBOOK_ARTICLE @@ -69,12 +69,12 @@ class SubscriptionDao( .orderBy(SUBSCRIPTION.CREATED_AT.desc()) .limit(1) - fun selectAllWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery): List { + fun selectAllWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery): List { return selectAllWorkbookSubscriptionStatusQuery(query) .fetchInto(MemberWorkbookSubscriptionStatusRecord::class.java) } - fun selectAllWorkbookSubscriptionStatusQuery(query: SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery) = + fun selectAllWorkbookSubscriptionStatusQuery(query: SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery) = dslContext.select( SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(MemberWorkbookSubscriptionStatusRecord::workbookId.name), SUBSCRIPTION.DELETED_AT.isNull.`as`(MemberWorkbookSubscriptionStatusRecord::isActiveSub.name), @@ -82,10 +82,11 @@ class SubscriptionDao( DSL.max(MAPPING_WORKBOOK_ARTICLE.DAY_COL).`as`(MemberWorkbookSubscriptionStatusRecord::totalDay.name) ) .from(SUBSCRIPTION) - .leftJoin(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE) + .join(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE) .on(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID)) .where(SUBSCRIPTION.MEMBER_ID.eq(query.memberId)) .and(SUBSCRIPTION.TARGET_MEMBER_ID.isNull) + .and(SUBSCRIPTION.UNSUBS_OPINION.`in`(query.unsubOpinion, query.activeSubscriptionUnsubOpinion)) .groupBy(SUBSCRIPTION.TARGET_WORKBOOK_ID, SUBSCRIPTION.DELETED_AT) .query diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery.kt deleted file mode 100644 index 063f23d69..000000000 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.few.api.repo.dao.subscription.query - -/** - * DeleteAt을 고려하지 않고 멤버의 모든 워크북 구독 상태를 조회하는 쿼리 - */ -data class SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery( - val memberId: Long, -) \ No newline at end of file diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery.kt new file mode 100644 index 000000000..eee092aca --- /dev/null +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery.kt @@ -0,0 +1,11 @@ +package com.few.api.repo.dao.subscription.query + +/** + * UnsubOpinion 조건을 만족하고 + * DeleteAt을 고려하지 않고 멤버의 모든 워크북 구독 상태를 조회하는 쿼리 + */ +data class SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery( + val memberId: Long, + val unsubOpinion: String = "receive.all", + val activeSubscriptionUnsubOpinion: String = "", +) \ No newline at end of file diff --git a/api-repo/src/test/kotlin/com/few/api/repo/explain/subscription/SubscriptionDaoExplainGenerateTest.kt b/api-repo/src/test/kotlin/com/few/api/repo/explain/subscription/SubscriptionDaoExplainGenerateTest.kt index 76dd2a8df..06a08e8ae 100644 --- a/api-repo/src/test/kotlin/com/few/api/repo/explain/subscription/SubscriptionDaoExplainGenerateTest.kt +++ b/api-repo/src/test/kotlin/com/few/api/repo/explain/subscription/SubscriptionDaoExplainGenerateTest.kt @@ -5,7 +5,7 @@ import com.few.api.repo.dao.subscription.command.InsertWorkbookSubscriptionComma import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInAllSubscriptionCommand import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery -import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery +import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery import com.few.api.repo.explain.InsertUpdateExplainGenerator import com.few.api.repo.explain.ResultGenerator import com.few.api.repo.jooq.JooqTestSpec @@ -62,7 +62,11 @@ class SubscriptionDaoExplainGenerateTest : JooqTestSpec() { @Test fun selectAllTopWorkbookSubscriptionStatusQueryExplain() { - val query = SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(memberId = 1L).let { + val query = SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery( + memberId = 1L, + unsubOpinion = "receive.all", + activeSubscriptionUnsubOpinion = "" + ).let { subscriptionDao.selectAllWorkbookSubscriptionStatusQuery(it) } diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/BrowseSubscribeWorkbooksUseCase.kt b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/BrowseSubscribeWorkbooksUseCase.kt index a9c203433..61bce9a10 100644 --- a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/BrowseSubscribeWorkbooksUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/BrowseSubscribeWorkbooksUseCase.kt @@ -8,7 +8,7 @@ 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.SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery +import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery import com.few.api.web.support.WorkBookStatus import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional @@ -22,7 +22,7 @@ class BrowseSubscribeWorkbooksUseCase( @Transactional fun execute(useCaseIn: BrowseSubscribeWorkbooksUseCaseIn): BrowseSubscribeWorkbooksUseCaseOut { val subscriptionRecords = - SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(useCaseIn.memberId).let { + SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery(useCaseIn.memberId).let { subscriptionDao.selectAllWorkbookSubscriptionStatus(it) } diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/service/WorkbookSubscribeService.kt b/api/src/main/kotlin/com/few/api/domain/workbook/service/WorkbookSubscribeService.kt index ac2cb4377..c23a4e021 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/service/WorkbookSubscribeService.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/service/WorkbookSubscribeService.kt @@ -3,7 +3,7 @@ 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.SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery +import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery import org.springframework.stereotype.Service @Service @@ -12,7 +12,7 @@ class WorkbookSubscribeService( ) { fun browseMemberSubscribeWorkbooks(dto: BrowseMemberSubscribeWorkbooksInDto): List { - return SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(dto.memberId).let { it -> + return SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery(dto.memberId).let { it -> subscriptionDao.selectAllWorkbookSubscriptionStatus(it).map { BrowseMemberSubscribeWorkbooksOutDto( workbookId = it.workbookId,