From 203300672bf7c3b7762a70f7be33b69662423114 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Wed, 7 Aug 2024 00:20:01 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EC=96=B4=EC=A7=84=20body=20=EC=8A=A4=ED=8E=99=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/subscription/SubscriptionController.kt | 3 --- .../subscription/request/SubscribeWorkbookRequest.kt | 10 ---------- .../subscription/SubscriptionControllerTest.kt | 3 --- 3 files changed, 16 deletions(-) delete mode 100644 api/src/main/kotlin/com/few/api/web/controller/subscription/request/SubscribeWorkbookRequest.kt diff --git a/api/src/main/kotlin/com/few/api/web/controller/subscription/SubscriptionController.kt b/api/src/main/kotlin/com/few/api/web/controller/subscription/SubscriptionController.kt index b18f8ee9c..88bf98f5e 100644 --- a/api/src/main/kotlin/com/few/api/web/controller/subscription/SubscriptionController.kt +++ b/api/src/main/kotlin/com/few/api/web/controller/subscription/SubscriptionController.kt @@ -1,7 +1,6 @@ package com.few.api.web.controller.subscription import com.few.api.domain.subscription.usecase.BrowseSubscribeWorkbooksUseCase -import com.few.api.web.controller.subscription.request.SubscribeWorkbookRequest import com.few.api.web.controller.subscription.request.UnsubscribeWorkbookRequest import com.few.api.web.support.ApiResponse import com.few.api.web.support.ApiResponseGenerator @@ -167,8 +166,6 @@ class SubscriptionController( @PathVariable(value = "workbookId") @Min(value = 1, message = "{min.id}") workbookId: Long, - @Valid @RequestBody - body: SubscribeWorkbookRequest, ): ApiResponse { val memberId = userDetails.username.toLong() subscribeWorkbookUseCase.execute( diff --git a/api/src/main/kotlin/com/few/api/web/controller/subscription/request/SubscribeWorkbookRequest.kt b/api/src/main/kotlin/com/few/api/web/controller/subscription/request/SubscribeWorkbookRequest.kt deleted file mode 100644 index d0f52ffa7..000000000 --- a/api/src/main/kotlin/com/few/api/web/controller/subscription/request/SubscribeWorkbookRequest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.few.api.web.controller.subscription.request - -import jakarta.validation.constraints.Email -import jakarta.validation.constraints.NotBlank - -data class SubscribeWorkbookRequest( - @field:NotBlank(message = "{email.notblank}") - @field:Email(message = "{email.invalid}") - val email: String, -) \ No newline at end of file diff --git a/api/src/test/kotlin/com/few/api/web/controller/subscription/SubscriptionControllerTest.kt b/api/src/test/kotlin/com/few/api/web/controller/subscription/SubscriptionControllerTest.kt index 34f4052a1..7284f0599 100644 --- a/api/src/test/kotlin/com/few/api/web/controller/subscription/SubscriptionControllerTest.kt +++ b/api/src/test/kotlin/com/few/api/web/controller/subscription/SubscriptionControllerTest.kt @@ -8,7 +8,6 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.few.api.domain.subscription.usecase.BrowseSubscribeWorkbooksUseCase import com.few.api.web.controller.ControllerTestSpec import com.few.api.web.controller.description.Description -import com.few.api.web.controller.subscription.request.SubscribeWorkbookRequest import com.few.api.web.controller.subscription.request.UnsubscribeWorkbookRequest import com.few.api.domain.subscription.usecase.SubscribeWorkbookUseCase import com.few.api.domain.subscription.usecase.UnsubscribeAllUseCase @@ -196,7 +195,6 @@ class SubscriptionControllerTest : ControllerTestSpec() { .build().toUriString() val email = "test@gmail.com" - val body = objectMapper.writeValueAsString(SubscribeWorkbookRequest(email = email)) // set usecase mock val memberId = 1L @@ -208,7 +206,6 @@ class SubscriptionControllerTest : ControllerTestSpec() { mockMvc.perform( post(uri, workbookId) .header("Authorization", "Bearer thisisaccesstoken") - .content(body) .contentType(MediaType.APPLICATION_JSON) ).andExpect(MockMvcResultMatchers.status().is2xxSuccessful) .andDo( From b3038020dec7a6dfcd1ecc0f18c42ee3d2994d7c Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Wed, 7 Aug 2024 00:21:35 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20unsubOpinion=EA=B3=BC=20activeS?= =?UTF-8?q?ubscriptionUnsubOpinion=EB=A5=BC=20=ED=86=B5=ED=95=B4=20?= =?UTF-8?q?=EA=B5=AC=EB=8F=85=20=EC=99=84=EB=A3=8C/=20=EA=B5=AC=EB=8F=85?= =?UTF-8?q?=20=EC=A4=91=20=EC=9B=8C=ED=81=AC=EB=B6=81=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../few/api/repo/dao/subscription/SubscriptionDao.kt | 9 +++++---- ...bookSubscriptionStatusNotConsiderDeletedAtQuery.kt | 8 -------- ...nsubOpinionConditionAndNotConsiderDeletedAQuery.kt | 11 +++++++++++ .../SubscriptionDaoExplainGenerateTest.kt | 8 ++++++-- .../usecase/BrowseSubscribeWorkbooksUseCase.kt | 4 ++-- .../workbook/service/WorkbookSubscribeService.kt | 4 ++-- 6 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery.kt create mode 100644 api-repo/src/main/kotlin/com/few/api/repo/dao/subscription/query/SelectAllMemberWorkbookSubscriptionStatusUnsubOpinionConditionAndNotConsiderDeletedAQuery.kt 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, From f779f9dc2fd41f9e27b6a98b7007e79e3d1962cb Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Wed, 7 Aug 2024 00:39:24 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20opinion=EC=9D=B4=20=EA=B3=B5?= =?UTF-8?q?=EB=B0=B1=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20cancel=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subscription/usecase/UnsubscribeAllUseCase.kt | 10 +++++++++- .../subscription/usecase/UnsubscribeWorkbookUseCase.kt | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeAllUseCase.kt b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeAllUseCase.kt index ce3301131..1887d9453 100644 --- a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeAllUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeAllUseCase.kt @@ -16,8 +16,16 @@ class UnsubscribeAllUseCase( @Transactional fun execute(useCaseIn: UnsubscribeAllUseCaseIn) { // TODO: request sending email + var opinion = useCaseIn.opinion + if (useCaseIn.opinion == "") { + opinion = "cancel" + } + subscriptionDao.updateDeletedAtInAllSubscription( - UpdateDeletedAtInAllSubscriptionCommand(memberId = useCaseIn.memberId, opinion = useCaseIn.opinion) + UpdateDeletedAtInAllSubscriptionCommand( + memberId = useCaseIn.memberId, + opinion = opinion + ) ) } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeWorkbookUseCase.kt b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeWorkbookUseCase.kt index 15d0c9051..ba5afb038 100644 --- a/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeWorkbookUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/subscription/usecase/UnsubscribeWorkbookUseCase.kt @@ -16,12 +16,16 @@ class UnsubscribeWorkbookUseCase( @Transactional fun execute(useCaseIn: UnsubscribeWorkbookUseCaseIn) { // TODO: request sending email + var opinion = useCaseIn.opinion + if (useCaseIn.opinion == "") { + opinion = "cancel" + } subscriptionDao.updateDeletedAtInWorkbookSubscription( UpdateDeletedAtInWorkbookSubscriptionCommand( memberId = useCaseIn.memberId, workbookId = useCaseIn.workbookId, - opinion = useCaseIn.opinion + opinion = opinion ) ) }