From 052072fa7d8cb9914a572c8d8212ff37668a9c6d Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:14:18 +0900 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20Workbooks=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/workbook/usecase/model/WorkBooks.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt new file mode 100644 index 00000000..e16cf00f --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model + +import com.few.api.domain.workbook.usecase.model.order.WorkbookOrderDelegator + +open class WorkBooks( + private val workbooks: List, +) { + fun order(delegator: WorkbookOrderDelegator): OrderedWorkBooks { + return delegator.order(workbooks) + } +} \ No newline at end of file From fe48a9116b92d0e3ad51b2832a9e0c38f5a8706b Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:15:20 +0900 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20Workbook?= =?UTF-8?q?OrderDelegator=20=EC=9D=B4=EB=8F=99=20=EB=B0=8F=20order=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=8B=9C=EA=B7=B8=EB=8B=88?= =?UTF-8?q?=EC=B3=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/model/order/WorkbookOrderDelegator.kt | 14 ++++++++++++++ .../service/order/WorkbookOrderDelegator.kt | 11 ----------- 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt new file mode 100644 index 00000000..a576eeb3 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt @@ -0,0 +1,14 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks +import com.few.api.domain.workbook.usecase.model.WorkBook + +interface WorkbookOrderDelegator { + + /** + * 워크북을 정렬합니다. + * @param workbooks 정렬할 워크북 목록 + * @return 정렬된 워크북 목록 + */ + fun order(workbooks: List): OrderedWorkBooks +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt deleted file mode 100644 index 1da8614c..00000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegator.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook - -interface WorkbookOrderDelegator { - - /** - * 워크북을 정렬합니다. - * */ - fun order(): List -} \ No newline at end of file From 838f7f26fc444119d5b29064210d3e0d6f5d1467 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:16:16 +0900 Subject: [PATCH 03/13] =?UTF-8?q?refactor:=20WorkbookOrderDelegator=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=B2=B4=20=EC=9D=B4=EB=8F=99=20=EB=B0=8F=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/AuthMainViewWorkbookOrderDelegator.kt | 11 ++++------- .../model/order/BasicWorkbookOrderDelegator.kt | 10 ++++++++++ .../service/order/BasicWorkbookOrderDelegator.kt | 11 ----------- .../service/order/WorkbookOrderDelegatorExecutor.kt | 12 ------------ 4 files changed, 14 insertions(+), 30 deletions(-) rename api/src/main/kotlin/com/few/api/domain/workbook/usecase/{service => model}/order/AuthMainViewWorkbookOrderDelegator.kt (88%) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt similarity index 88% rename from api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt rename to api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt index fe44f1f5..e815c869 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegator.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt @@ -1,13 +1,10 @@ -package com.few.api.domain.workbook.usecase.service.order +package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook +import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks import com.few.api.domain.workbook.usecase.model.WorkBook class AuthMainViewWorkbookOrderDelegator( - /** - * @see com.few.api.repo.dao.workbook.WorkbookDao.browseWorkBookWithSubscriptionCount - */ - private val workbooks: List, private val memberSubscribedWorkbooks: List, ) : WorkbookOrderDelegator { @@ -18,7 +15,7 @@ class AuthMainViewWorkbookOrderDelegator( * 2. 구독 기록이 없는 워크북을 보여줍니다. * 3. 비활성화된 구독 워크북을 보여줍니다. */ - override fun order(): List { + override fun order(workbooks: List): OrderedWorkBooks { val allWorkbookIds = workbooks.associate { it.id to false }.toMutableMap() val activeSubWorkbookIds = memberSubscribedWorkbooks.filter { it.isActiveSub }.sortedByDescending { @@ -64,6 +61,6 @@ class AuthMainViewWorkbookOrderDelegator( */ orderedWorkbooks.addAll(lastAddWorkbooks) - return orderedWorkbooks + return OrderedWorkBooks(orderedWorkbooks) } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt new file mode 100644 index 00000000..29cc0536 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt @@ -0,0 +1,10 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks +import com.few.api.domain.workbook.usecase.model.WorkBook + +class BasicWorkbookOrderDelegator : WorkbookOrderDelegator { + override fun order(workbooks: List): OrderedWorkBooks { + return OrderedWorkBooks(workbooks) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt deleted file mode 100644 index daae0709..00000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/BasicWorkbookOrderDelegator.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook - -class BasicWorkbookOrderDelegator( - private val workbooks: List, -) : WorkbookOrderDelegator { - override fun order(): List { - return workbooks - } -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt deleted file mode 100644 index cf37cd2e..00000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/order/WorkbookOrderDelegatorExecutor.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.few.api.domain.workbook.usecase.service.order - -import com.few.api.domain.workbook.usecase.model.WorkBook -import org.springframework.stereotype.Service - -@Service -class WorkbookOrderDelegatorExecutor { - - fun execute(delegator: WorkbookOrderDelegator): List { - return delegator.order() - } -} \ No newline at end of file From 92e0f68a588d5d0eae46b36889fa553108ebc7ec Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:16:47 +0900 Subject: [PATCH 04/13] =?UTF-8?q?feat:=20OrderedWorkBooks=20=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/workbook/usecase/model/OrderedWorkBooks.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt new file mode 100644 index 00000000..1208962a --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt @@ -0,0 +1,5 @@ +package com.few.api.domain.workbook.usecase.model + +class OrderedWorkBooks( + val workbooks: List, +) : WorkBooks(workbooks) \ No newline at end of file From 6f79d974b9ce9fa55dad9964410fa3f804b94b1e Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:17:21 +0900 Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20BrowseWorkbooksUseCase?= =?UTF-8?q?=EC=97=90=20=EB=B3=80=EA=B2=BD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BrowseWorkbooksUseCase.kt | 109 ++++++++++-------- 1 file changed, 64 insertions(+), 45 deletions(-) diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt index 5aa097dc..748550f4 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt @@ -4,16 +4,18 @@ import com.few.api.domain.workbook.service.WorkbookMemberService import com.few.api.domain.workbook.service.WorkbookSubscribeService import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksInDto import com.few.api.domain.workbook.service.dto.BrowseWorkbookWriterRecordsInDto +import com.few.api.domain.workbook.service.dto.WriterMappedWorkbookOutDto import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseOut import com.few.api.domain.workbook.usecase.dto.WriterDetail import com.few.api.domain.workbook.usecase.model.* -import com.few.api.domain.workbook.usecase.service.order.AuthMainViewWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.BasicWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.WorkbookOrderDelegatorExecutor +import com.few.api.domain.workbook.usecase.model.order.AuthMainViewWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.model.order.BasicWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.model.order.WorkbookOrderDelegator import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery +import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount import com.few.api.web.support.ViewCategory import com.few.data.common.code.CategoryType import org.springframework.stereotype.Component @@ -42,7 +44,6 @@ class BrowseWorkbooksUseCase( private val workbookDao: WorkbookDao, private val workbookMemberService: WorkbookMemberService, private val workbookSubscribeService: WorkbookSubscribeService, - private val workbookOrderDelegatorExecutor: WorkbookOrderDelegatorExecutor, ) { @Transactional @@ -56,54 +57,21 @@ class BrowseWorkbooksUseCase( BrowseWorkbookWriterRecordsInDto(workbookIds) ) - val workbookDetails = workbookRecords.map { record -> - WorkBook( - id = record.id, - mainImageUrl = record.mainImageUrl, - title = record.title, - description = record.description, - category = CategoryType.convertToDisplayName(record.category), - createdAt = record.createdAt, - writerDetails = writerRecords[record.id]?.map { - WorkBookWriter( - id = it.writerId, - name = it.name, - url = it.url - ) - } ?: emptyList(), - subscriptionCount = record.subscriptionCount - ) - } + val workbooks = toWorkbooks(workbookRecords, writerRecords) - val orderStrategy = when { - useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId != null -> WorkBookOrderStrategy.MAIN_VIEW_AUTH - useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId == null -> WorkBookOrderStrategy.MAIN_VIEW_UNAUTH - else -> WorkBookOrderStrategy.BASIC - } - - val orderedWorkbooks = when (orderStrategy) { + val orderStrategy = getOrderStrategy(useCaseIn) + val orderDelegator = when (orderStrategy) { WorkBookOrderStrategy.MAIN_VIEW_AUTH -> { - BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> - workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) - }.map { - MemberSubscribedWorkbook( - workbookId = it.workbookId, - isActiveSub = it.isActiveSub, - currentDay = it.currentDay - ) - }.let { subscribedWorkbooks -> - AuthMainViewWorkbookOrderDelegator(workbookDetails, subscribedWorkbooks) - } + genAuthMainViewWorkbookOrderDelegator(useCaseIn) } WorkBookOrderStrategy.MAIN_VIEW_UNAUTH -> { - BasicWorkbookOrderDelegator(workbookDetails) + genBasicWorkbookOrderDelegator() } - else -> BasicWorkbookOrderDelegator(workbookDetails) - }.let { delegator -> - workbookOrderDelegatorExecutor.execute(delegator) + else -> genBasicWorkbookOrderDelegator() } - orderedWorkbooks.map { workBook -> + val orderedWorkbooks = workbooks.order(orderDelegator) + orderedWorkbooks.workbooks.map { workBook -> BrowseWorkBookDetail( id = workBook.id, mainImageUrl = workBook.mainImageUrl, @@ -126,4 +94,55 @@ class BrowseWorkbooksUseCase( ) } } + + private fun getOrderStrategy(useCaseIn: BrowseWorkbooksUseCaseIn) = + when { + useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId != null -> WorkBookOrderStrategy.MAIN_VIEW_AUTH + useCaseIn.viewCategory == ViewCategory.MAIN_CARD && useCaseIn.memberId == null -> WorkBookOrderStrategy.MAIN_VIEW_UNAUTH + else -> WorkBookOrderStrategy.BASIC + } + + private fun toWorkbooks( + workbookRecords: List, + writerRecords: Map>, + ): WorkBooks { + return workbookRecords.map { record -> + WorkBook( + id = record.id, + mainImageUrl = record.mainImageUrl, + title = record.title, + description = record.description, + category = CategoryType.convertToDisplayName(record.category), + createdAt = record.createdAt, + writerDetails = writerRecords[record.id]?.map { + WorkBookWriter( + id = it.writerId, + name = it.name, + url = it.url + ) + } ?: emptyList(), + subscriptionCount = record.subscriptionCount + ) + }.let { + WorkBooks(it) + } + } + + private fun genBasicWorkbookOrderDelegator(): WorkbookOrderDelegator { + return BasicWorkbookOrderDelegator() + } + + private fun genAuthMainViewWorkbookOrderDelegator(useCaseIn: BrowseWorkbooksUseCaseIn): WorkbookOrderDelegator { + return BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> + workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) + }.map { + MemberSubscribedWorkbook( + workbookId = it.workbookId, + isActiveSub = it.isActiveSub, + currentDay = it.currentDay + ) + }.let { subscribedWorkbooks -> + AuthMainViewWorkbookOrderDelegator(subscribedWorkbooks) + } + } } \ No newline at end of file From ee3acee2c6228af09b1e6a2714f63347f47033a8 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sat, 28 Sep 2024 21:17:42 +0900 Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BrowseWorkbooksUseCaseTest.kt | 104 +----------------- .../AuthMainViewWorkbookOrderDelegatorTest.kt | 23 ++-- 2 files changed, 16 insertions(+), 111 deletions(-) rename api/src/test/kotlin/com/few/api/domain/workbook/usecase/{service => model}/order/AuthMainViewWorkbookOrderDelegatorTest.kt (90%) diff --git a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt index bef68a2e..54c70494 100644 --- a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCaseTest.kt @@ -5,11 +5,6 @@ import com.few.api.domain.workbook.service.WorkbookSubscribeService import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksOutDto import com.few.api.domain.workbook.service.dto.WriterMappedWorkbookOutDto import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn -import com.few.api.domain.workbook.usecase.model.WorkBook -import com.few.api.domain.workbook.usecase.model.WorkBookWriter -import com.few.api.domain.workbook.usecase.service.order.AuthMainViewWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.BasicWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.service.order.WorkbookOrderDelegatorExecutor import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount import com.few.api.web.support.ViewCategory @@ -29,16 +24,14 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ lateinit var workbookDao: WorkbookDao lateinit var workbookMemberService: WorkbookMemberService lateinit var workbookSubscribeService: WorkbookSubscribeService - lateinit var workbookOrderDelegatorExecutor: WorkbookOrderDelegatorExecutor lateinit var useCase: BrowseWorkbooksUseCase beforeContainer { workbookDao = mockk() workbookMemberService = mockk() workbookSubscribeService = mockk() - workbookOrderDelegatorExecutor = mockk() useCase = - BrowseWorkbooksUseCase(workbookDao, workbookMemberService, workbookSubscribeService, workbookOrderDelegatorExecutor) + BrowseWorkbooksUseCase(workbookDao, workbookMemberService, workbookSubscribeService) } given("메인 뷰에서 로그인 된 상태로 카테고리를 지정하여 다수 워크북 조회 요청이 온 상황에서") { @@ -63,16 +56,16 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ 1L to listOf( WriterMappedWorkbookOutDto( writerId = 1L, - name = "hunca", - url = URL("https://jh-labs.tistory.com/"), + name = "writer1", + url = URL("http://localhost:8080/image/writer/1"), workbookId = 1L ) ), 2L to listOf( WriterMappedWorkbookOutDto( writerId = 2L, - name = "hunca", - url = URL("https://jh-labs.tistory.com/"), + name = "writer2", + url = URL("http://localhost:8080/image/writer/2"), workbookId = 2L ) ) @@ -93,27 +86,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ ) ) - every { - workbookOrderDelegatorExecutor.execute(any(AuthMainViewWorkbookOrderDelegator::class)) - } returns IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("https://jh-labs.tistory.com/") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -127,20 +99,13 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ browseWorkBookDetail.writerDetails.size shouldBe 1 browseWorkBookDetail.writerDetails[0].id shouldBe (index + 1).toLong() browseWorkBookDetail.writerDetails[0].name shouldBe "writer${index + 1}" - browseWorkBookDetail.writerDetails[0].url shouldBe URL("https://jh-labs.tistory.com/") + browseWorkBookDetail.writerDetails[0].url shouldBe URL("http://localhost:8080/image/writer/${index + 1}") browseWorkBookDetail.subscriptionCount shouldBe (index + 1).toLong() } verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 1) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - AuthMainViewWorkbookOrderDelegator::class - ) - ) - } } } } @@ -176,28 +141,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ } every { workbookMemberService.browseWorkbookWriterRecords(any()) } returns workbookWriterRecords - every { - workbookOrderDelegatorExecutor.execute(any(BasicWorkbookOrderDelegator::class)) - } returns - IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("http://localhost:8080/image/writer/$it") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -218,13 +161,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 0) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - BasicWorkbookOrderDelegator::class - ) - ) - } } } } @@ -268,27 +204,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ ) ) - every { - workbookOrderDelegatorExecutor.execute(any(BasicWorkbookOrderDelegator::class)) - } returns IntStream.range(1, 1 + workbookCount).mapToObj { - WorkBook( - id = it.toLong(), - title = "workbook title$it", - mainImageUrl = URL("http://localhost:8080/image/main/$it"), - category = WorkBookCategory.ECONOMY.displayName, - description = "workbook$it description", - createdAt = LocalDateTime.now(), - writerDetails = listOf( - WorkBookWriter( - id = it.toLong(), - name = "writer$it", - url = URL("http://localhost:8080/image/writer/$it") - ) - ), - subscriptionCount = it.toLong() - ) - }.toList() - then("경제 카테고리의 워크북이 조회된다") { val useCaseOut = useCase.execute(useCaseIn) useCaseOut.workbooks.size shouldBe workbookCount @@ -308,13 +223,6 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } verify(exactly = 0) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } - verify(exactly = 1) { - workbookOrderDelegatorExecutor.execute( - any( - BasicWorkbookOrderDelegator::class - ) - ) - } } } } diff --git a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt similarity index 90% rename from api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt rename to api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt index e1402a94..95b33ee8 100644 --- a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/service/order/AuthMainViewWorkbookOrderDelegatorTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt @@ -1,4 +1,4 @@ -package com.few.api.domain.workbook.usecase.service.order +package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook import com.few.api.domain.workbook.usecase.model.WorkBook @@ -55,17 +55,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds + inActiveList for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) } } @@ -115,17 +114,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) } } @@ -175,17 +173,16 @@ class AuthMainViewWorkbookOrderDelegatorTest { // when val delegator = AuthMainViewWorkbookOrderDelegator( - workbooksOrderBySubscriptionCount, memberSubscribedWorkbooksReverseOrderByCurrentDay ) // then - val orderedWorkbooks = delegator.order() - assertEquals(totalWorkbookCount, orderedWorkbooks.size) + val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) val expectedOrderedWorkbookIds = notSubscribeWorkbookIds + inActiveWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) } } } \ No newline at end of file From 55a1c04baa919282b12122c40115ac2e9bec62a5 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:45:50 +0900 Subject: [PATCH 07/13] =?UTF-8?q?refactor:=20WorkBook=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=B2=94=EC=9A=A9=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/workbook/usecase/model/WorkBooks.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt index e16cf00f..8a3bd807 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkBooks.kt @@ -1,11 +1,5 @@ package com.few.api.domain.workbook.usecase.model -import com.few.api.domain.workbook.usecase.model.order.WorkbookOrderDelegator - -open class WorkBooks( - private val workbooks: List, -) { - fun order(delegator: WorkbookOrderDelegator): OrderedWorkBooks { - return delegator.order(workbooks) - } -} \ No newline at end of file +data class WorkBooks( + val workbookData: List, +) \ No newline at end of file From 11a473dc638896b88e352de6b9e4e37ccd00c6e5 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:46:33 +0900 Subject: [PATCH 08/13] =?UTF-8?q?feat:=20order=20=EB=AA=A8=EB=8D=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=95=A0=20OrderTargetW?= =?UTF-8?q?orkBooks=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workbook/usecase/model/order/OrderTargetWorkBooks.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt new file mode 100644 index 00000000..7e82be42 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderTargetWorkBooks.kt @@ -0,0 +1,7 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.WorkBooks + +data class OrderTargetWorkBooks( + val workbooks: WorkBooks, +) \ No newline at end of file From a43310f4ab98f2d346b8467ff77c9d2d723aeb40 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:47:06 +0900 Subject: [PATCH 09/13] =?UTF-8?q?feat:=20order=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workbook/usecase/model/order/OrderAbleWorkBooks.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt new file mode 100644 index 00000000..190a2585 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderAbleWorkBooks.kt @@ -0,0 +1,5 @@ +package com.few.api.domain.workbook.usecase.model.order + +open class OrderAbleWorkBooks( + protected open val targetWorkBooks: OrderTargetWorkBooks, +) \ No newline at end of file From 3d67632216789a61dcf035854c4e345fcc6624f7 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:47:37 +0900 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20order=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/workbook/usecase/model/OrderedWorkBooks.kt | 5 ----- .../model/order/AuthMainViewWorkbookOrderDelegator.kt | 7 ++++--- .../workbook/usecase/model/order/OrderedWorkBooks.kt | 9 +++++++++ .../usecase/model/order/UnOrderedWorkBooks.kt | 11 +++++++++++ .../usecase/model/order/WorkbookOrderDelegator.kt | 7 ++----- 5 files changed, 26 insertions(+), 13 deletions(-) delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt create mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt deleted file mode 100644 index 1208962a..00000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/OrderedWorkBooks.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.few.api.domain.workbook.usecase.model - -class OrderedWorkBooks( - val workbooks: List, -) : WorkBooks(workbooks) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt index e815c869..9f3bb951 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegator.kt @@ -1,8 +1,8 @@ package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook -import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks import com.few.api.domain.workbook.usecase.model.WorkBook +import com.few.api.domain.workbook.usecase.model.WorkBooks class AuthMainViewWorkbookOrderDelegator( private val memberSubscribedWorkbooks: List, @@ -15,7 +15,8 @@ class AuthMainViewWorkbookOrderDelegator( * 2. 구독 기록이 없는 워크북을 보여줍니다. * 3. 비활성화된 구독 워크북을 보여줍니다. */ - override fun order(workbooks: List): OrderedWorkBooks { + override fun order(targetWorkBooks: OrderTargetWorkBooks): OrderTargetWorkBooks { + val workbooks = targetWorkBooks.workbooks.workbookData val allWorkbookIds = workbooks.associate { it.id to false }.toMutableMap() val activeSubWorkbookIds = memberSubscribedWorkbooks.filter { it.isActiveSub }.sortedByDescending { @@ -61,6 +62,6 @@ class AuthMainViewWorkbookOrderDelegator( */ orderedWorkbooks.addAll(lastAddWorkbooks) - return OrderedWorkBooks(orderedWorkbooks) + return OrderTargetWorkBooks(WorkBooks(orderedWorkbooks)) } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt new file mode 100644 index 00000000..66dafe10 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/OrderedWorkBooks.kt @@ -0,0 +1,9 @@ +package com.few.api.domain.workbook.usecase.model.order + +import com.few.api.domain.workbook.usecase.model.WorkBooks + +class OrderedWorkBooks( + orderTargetWorkBooks: OrderTargetWorkBooks, +) : OrderAbleWorkBooks(orderTargetWorkBooks) { + val orderedWorkbooks: WorkBooks = orderTargetWorkBooks.workbooks +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt new file mode 100644 index 00000000..ae72f2ec --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/UnOrderedWorkBooks.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model.order + +class UnOrderedWorkBooks( + orderTargetWorkBooks: OrderTargetWorkBooks, + private val delegator: WorkbookOrderDelegator, +) : OrderAbleWorkBooks(orderTargetWorkBooks) { + fun order(): OrderedWorkBooks { + val orderedWorkbooks = delegator.order(targetWorkBooks) + return OrderedWorkBooks(orderedWorkbooks) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt index a576eeb3..df281f9c 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/WorkbookOrderDelegator.kt @@ -1,14 +1,11 @@ package com.few.api.domain.workbook.usecase.model.order -import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks -import com.few.api.domain.workbook.usecase.model.WorkBook - interface WorkbookOrderDelegator { /** * 워크북을 정렬합니다. - * @param workbooks 정렬할 워크북 목록 + * @param targetWorkBooks 정렬할 워크북 목록 * @return 정렬된 워크북 목록 */ - fun order(workbooks: List): OrderedWorkBooks + fun order(targetWorkBooks: OrderTargetWorkBooks): OrderTargetWorkBooks } \ No newline at end of file From 433c3ba5f6f16d69a3d470e195fe19f3d65dece6 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:47:51 +0900 Subject: [PATCH 11/13] =?UTF-8?q?refactor:=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/BrowseWorkbooksUseCase.kt | 61 ++++++++++--------- .../order/BasicWorkbookOrderDelegator.kt | 10 --- 2 files changed, 32 insertions(+), 39 deletions(-) delete mode 100644 api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt index 748550f4..b4ab0c8f 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt @@ -10,9 +10,7 @@ import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseOut import com.few.api.domain.workbook.usecase.dto.WriterDetail import com.few.api.domain.workbook.usecase.model.* -import com.few.api.domain.workbook.usecase.model.order.AuthMainViewWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.model.order.BasicWorkbookOrderDelegator -import com.few.api.domain.workbook.usecase.model.order.WorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.model.order.* import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount @@ -57,21 +55,30 @@ class BrowseWorkbooksUseCase( BrowseWorkbookWriterRecordsInDto(workbookIds) ) - val workbooks = toWorkbooks(workbookRecords, writerRecords) - val orderStrategy = getOrderStrategy(useCaseIn) val orderDelegator = when (orderStrategy) { WorkBookOrderStrategy.MAIN_VIEW_AUTH -> { genAuthMainViewWorkbookOrderDelegator(useCaseIn) } - WorkBookOrderStrategy.MAIN_VIEW_UNAUTH -> { - genBasicWorkbookOrderDelegator() - } - else -> genBasicWorkbookOrderDelegator() + /** BASIC, MAIN_VIEW_UNAUTH -> 해당 경우는 DB 조회 결과를 그대로 반환 */ + else -> null + } + + val workbooks = toWorkbooks(workbookRecords, writerRecords) + + val orderedWorkbook = OrderTargetWorkBooks(workbooks).let { target -> + orderDelegator + ?.let { delegator -> + UnOrderedWorkBooks( + target, + delegator + ).order().orderedWorkbooks + } + ?: run { OrderedWorkBooks(target).orderedWorkbooks } } - val orderedWorkbooks = workbooks.order(orderDelegator) - orderedWorkbooks.workbooks.map { workBook -> + val orderedWorkbookData = orderedWorkbook.workbookData + orderedWorkbookData.map { workBook -> BrowseWorkBookDetail( id = workBook.id, mainImageUrl = workBook.mainImageUrl, @@ -102,6 +109,20 @@ class BrowseWorkbooksUseCase( else -> WorkBookOrderStrategy.BASIC } + private fun genAuthMainViewWorkbookOrderDelegator(useCaseIn: BrowseWorkbooksUseCaseIn): WorkbookOrderDelegator { + return BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> + workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) + }.map { + MemberSubscribedWorkbook( + workbookId = it.workbookId, + isActiveSub = it.isActiveSub, + currentDay = it.currentDay + ) + }.let { subscribedWorkbooks -> + AuthMainViewWorkbookOrderDelegator(subscribedWorkbooks) + } + } + private fun toWorkbooks( workbookRecords: List, writerRecords: Map>, @@ -127,22 +148,4 @@ class BrowseWorkbooksUseCase( WorkBooks(it) } } - - private fun genBasicWorkbookOrderDelegator(): WorkbookOrderDelegator { - return BasicWorkbookOrderDelegator() - } - - private fun genAuthMainViewWorkbookOrderDelegator(useCaseIn: BrowseWorkbooksUseCaseIn): WorkbookOrderDelegator { - return BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> - workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) - }.map { - MemberSubscribedWorkbook( - workbookId = it.workbookId, - isActiveSub = it.isActiveSub, - currentDay = it.currentDay - ) - }.let { subscribedWorkbooks -> - AuthMainViewWorkbookOrderDelegator(subscribedWorkbooks) - } - } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt deleted file mode 100644 index 29cc0536..00000000 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/order/BasicWorkbookOrderDelegator.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.few.api.domain.workbook.usecase.model.order - -import com.few.api.domain.workbook.usecase.model.OrderedWorkBooks -import com.few.api.domain.workbook.usecase.model.WorkBook - -class BasicWorkbookOrderDelegator : WorkbookOrderDelegator { - override fun order(workbooks: List): OrderedWorkBooks { - return OrderedWorkBooks(workbooks) - } -} \ No newline at end of file From 60f3388ff0cb43ba1e3693e621360f0ef81df7f0 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 11:53:45 +0900 Subject: [PATCH 12/13] =?UTF-8?q?refactor:=20orderedWorkbooks=20=EA=B3=B5?= =?UTF-8?q?=ED=86=B5=EC=9C=BC=EB=A1=9C=20=EC=B2=98=EB=A6=AC=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=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 --- .../api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt index b4ab0c8f..15a5aa00 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/BrowseWorkbooksUseCase.kt @@ -72,10 +72,10 @@ class BrowseWorkbooksUseCase( UnOrderedWorkBooks( target, delegator - ).order().orderedWorkbooks + ).order() } - ?: run { OrderedWorkBooks(target).orderedWorkbooks } - } + ?: run { OrderedWorkBooks(target) } + }.orderedWorkbooks val orderedWorkbookData = orderedWorkbook.workbookData orderedWorkbookData.map { workBook -> From d24e5d3887ec0c5d348fe3ac53667757c8ca350f Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 30 Sep 2024 12:01:52 +0900 Subject: [PATCH 13/13] =?UTF-8?q?fix:=20=EB=B3=80=EA=B2=BD=20=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthMainViewWorkbookOrderDelegatorTest.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt index 95b33ee8..39218116 100644 --- a/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt +++ b/api/src/test/kotlin/com/few/api/domain/workbook/usecase/model/order/AuthMainViewWorkbookOrderDelegatorTest.kt @@ -2,6 +2,7 @@ package com.few.api.domain.workbook.usecase.model.order import com.few.api.domain.workbook.usecase.model.MemberSubscribedWorkbook import com.few.api.domain.workbook.usecase.model.WorkBook +import com.few.api.domain.workbook.usecase.model.WorkBooks import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import java.net.URL @@ -59,12 +60,12 @@ class AuthMainViewWorkbookOrderDelegatorTest { ) // then - val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) - assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds + inActiveList for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } @@ -118,12 +119,12 @@ class AuthMainViewWorkbookOrderDelegatorTest { ) // then - val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) - assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = activeWorkbookIds + notSubscribeWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } @@ -177,12 +178,12 @@ class AuthMainViewWorkbookOrderDelegatorTest { ) // then - val orderedWorkbooks = delegator.order(workbooksOrderBySubscriptionCount) - assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.size) + val orderedWorkbooks = delegator.order(OrderTargetWorkBooks(WorkBooks(workbooksOrderBySubscriptionCount))) + assertEquals(totalWorkbookCount, orderedWorkbooks.workbooks.workbookData.size) val expectedOrderedWorkbookIds = notSubscribeWorkbookIds + inActiveWorkbookIds for (i in expectedOrderedWorkbookIds.indices) { - assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks[i].id) + assertEquals(expectedOrderedWorkbookIds[i].toLong(), orderedWorkbooks.workbooks.workbookData[i].id) } } } \ No newline at end of file