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 new file mode 100644 index 000000000..ac2cb4377 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/service/WorkbookSubscribeService.kt @@ -0,0 +1,25 @@ +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 org.springframework.stereotype.Service + +@Service +class WorkbookSubscribeService( + private val subscriptionDao: SubscriptionDao, +) { + + fun browseMemberSubscribeWorkbooks(dto: BrowseMemberSubscribeWorkbooksInDto): List { + return SelectAllMemberWorkbookSubscriptionStatusNotConsiderDeletedAtQuery(dto.memberId).let { it -> + subscriptionDao.selectAllWorkbookSubscriptionStatus(it).map { + BrowseMemberSubscribeWorkbooksOutDto( + workbookId = it.workbookId, + isActiveSub = it.isActiveSub, + currentDay = it.currentDay + ) + } + } + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksInDto.kt b/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksInDto.kt new file mode 100644 index 000000000..2168acd1b --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksInDto.kt @@ -0,0 +1,5 @@ +package com.few.api.domain.workbook.service.dto + +data class BrowseMemberSubscribeWorkbooksInDto( + val memberId: Long, +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksOutDto.kt b/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksOutDto.kt new file mode 100644 index 000000000..323db3e6e --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/service/dto/BrowseMemberSubscribeWorkbooksOutDto.kt @@ -0,0 +1,7 @@ +package com.few.api.domain.workbook.service.dto + +data class BrowseMemberSubscribeWorkbooksOutDto( + val workbookId: Long, + val isActiveSub: Boolean, + val currentDay: Int, +) \ No newline at end of file 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 ae60264fa..2bf5deb4e 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 @@ -1,21 +1,47 @@ package com.few.api.domain.workbook.usecase 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.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.BasicWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.model.AuthMainViewWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.service.WorkbookOrderDelegatorExecutor import com.few.api.repo.dao.workbook.WorkbookDao import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCount +import com.few.api.web.support.ViewCategory import com.few.data.common.code.CategoryType import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional +enum class WorkBookOrderStrategy { + BASIC, + + /** + * 로그인 상태에서 메인 화면에 보여질 워크북을 정렬합니다. + * - view의 값이 MAIN_CARD이다. + * - memberId가 null이 아니다. + * */ + MAIN_VIEW_AUTH, + + /** + * 비로그인 상태에서 메인 화면에 보여질 워크북을 정렬합니다. + * - view의 값이 MAIN_CARD이다. + * - memberId가 null이다. + */ + MAIN_VIEW_UNAUTH, +} + @Component class BrowseWorkbooksUseCase( private val workbookDao: WorkbookDao, private val workbookMemberService: WorkbookMemberService, + private val workbookSubscribeService: WorkbookSubscribeService, + private val workbookOrderDelegatorExecutor: WorkbookOrderDelegatorExecutor, ) { @Transactional @@ -48,8 +74,30 @@ class BrowseWorkbooksUseCase( ) } + 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) { + WorkBookOrderStrategy.MAIN_VIEW_AUTH -> { + BrowseMemberSubscribeWorkbooksInDto(useCaseIn.memberId!!).let { dto -> + workbookSubscribeService.browseMemberSubscribeWorkbooks(dto) + }.let { memberSubscribeWorkbooks -> + AuthMainViewWorkbookOrderDelegator(workbookDetails, memberSubscribeWorkbooks) + } + } + WorkBookOrderStrategy.MAIN_VIEW_UNAUTH -> { + BasicWorkbookOrderDelegator(workbookDetails) + } + else -> BasicWorkbookOrderDelegator(workbookDetails) + }.let { delegator -> + workbookOrderDelegatorExecutor.execute(delegator) + } + return BrowseWorkbooksUseCaseOut( - workbooks = workbookDetails + workbooks = orderedWorkbooks ) } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/dto/BrowseWorkbooksUseCaseIn.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/dto/BrowseWorkbooksUseCaseIn.kt index be3820712..4c073ab26 100644 --- a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/dto/BrowseWorkbooksUseCaseIn.kt +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/dto/BrowseWorkbooksUseCaseIn.kt @@ -1,7 +1,10 @@ package com.few.api.domain.workbook.usecase.dto +import com.few.api.web.support.ViewCategory import com.few.api.web.support.WorkBookCategory data class BrowseWorkbooksUseCaseIn( val category: WorkBookCategory, + val viewCategory: ViewCategory?, + val memberId: Long?, ) \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/AuthMainViewWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/AuthMainViewWorkbookOrderDelegator.kt new file mode 100644 index 000000000..5608522e7 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/AuthMainViewWorkbookOrderDelegator.kt @@ -0,0 +1,66 @@ +package com.few.api.domain.workbook.usecase.model + +import com.few.api.domain.workbook.service.dto.BrowseMemberSubscribeWorkbooksOutDto +import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail + +class AuthMainViewWorkbookOrderDelegator( + /** + * @see com.few.api.repo.dao.workbook.WorkbookDao.browseWorkBookWithSubscriptionCount + */ + private val workbooks: List, + private val memberSubscribeWorkbooks: List, +) : WorkbookOrderDelegator { + + /** + * 메인 화면에 보여질 워크북을 정렬합니다. + * 1. 활성화된 구독 워크북을 먼저 보여줍니다. + * 2. 구독 기록이 없는 워크북을 보여줍니다. + * 3. 비활성화된 구독 워크북을 보여줍니다. + */ + override fun order(): List { + val allWorkbookIds = workbooks.associate { it.id to false }.toMutableMap() + val activeSubWorkbookIds = memberSubscribeWorkbooks.filter { it.isActiveSub }.sortedByDescending { + it.currentDay + }.map { it.workbookId } + val inActiveSubWorkbookIds = memberSubscribeWorkbooks.filter { !it.isActiveSub }.map { it.workbookId } + + val orderedWorkbooks = mutableListOf() + + /** + * 활성화된 구독 워크북을 먼저 보여줍니다. + */ + activeSubWorkbookIds.forEach { activeSubWorkbookId -> + workbooks.find { it.id == activeSubWorkbookId }?.let { + orderedWorkbooks.add(it) + allWorkbookIds[activeSubWorkbookId] = true + } + } + + /** + * 비활성화된 구독 워크북을 모아둡니다. + */ + val lastAddWorkbooks = mutableListOf() + inActiveSubWorkbookIds.forEach { inActiveSubWorkbookId -> + workbooks.find { it.id == inActiveSubWorkbookId }?.let { + lastAddWorkbooks.add(it) + allWorkbookIds[inActiveSubWorkbookId] = true + } + } + + /** + * 구독 기록이 없는 워크북을 보여줍니다. + */ + allWorkbookIds.filter { !it.value }.forEach { (id, _) -> + workbooks.find { it.id == id }?.let { + orderedWorkbooks.add(it) + } + } + + /** + * 비활성화된 구독 워크북을 보여줍니다. + */ + orderedWorkbooks.addAll(lastAddWorkbooks) + + return orderedWorkbooks + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/BasicWorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/BasicWorkbookOrderDelegator.kt new file mode 100644 index 000000000..505e4aa1a --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/BasicWorkbookOrderDelegator.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model + +import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail + +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/model/WorkbookOrderDelegator.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkbookOrderDelegator.kt new file mode 100644 index 000000000..ffd458bc8 --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/model/WorkbookOrderDelegator.kt @@ -0,0 +1,11 @@ +package com.few.api.domain.workbook.usecase.model + +import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail + +interface WorkbookOrderDelegator { + + /** + * 워크북을 정렬합니다. + * */ + fun order(): List +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/WorkbookOrderDelegatorExecutor.kt b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/WorkbookOrderDelegatorExecutor.kt new file mode 100644 index 000000000..050d5bbfb --- /dev/null +++ b/api/src/main/kotlin/com/few/api/domain/workbook/usecase/service/WorkbookOrderDelegatorExecutor.kt @@ -0,0 +1,13 @@ +package com.few.api.domain.workbook.usecase.service + +import com.few.api.domain.workbook.usecase.dto.BrowseWorkBookDetail +import com.few.api.domain.workbook.usecase.model.WorkbookOrderDelegator +import org.springframework.stereotype.Service + +@Service +class WorkbookOrderDelegatorExecutor { + + fun execute(delegator: WorkbookOrderDelegator): List { + return delegator.order() + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt b/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt index d99db6cdb..55507d5db 100644 --- a/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt +++ b/api/src/main/kotlin/com/few/api/web/controller/workbook/WorkBookController.kt @@ -8,6 +8,7 @@ import com.few.api.web.controller.workbook.response.* import com.few.api.web.support.WorkBookCategory import com.few.api.web.support.ApiResponse import com.few.api.web.support.ApiResponseGenerator +import com.few.api.web.support.ViewCategory import jakarta.validation.constraints.Min import org.springframework.http.HttpStatus import org.springframework.http.MediaType @@ -45,9 +46,12 @@ class WorkBookController( fun browseWorkBooks( @RequestParam(value = "category", required = false) category: WorkBookCategory?, + @RequestParam(value = "view", required = false) + viewCategory: ViewCategory?, ): ApiResponse> { val useCaseOut = - BrowseWorkbooksUseCaseIn(category ?: WorkBookCategory.All).let { useCaseIn -> + // todo fix memberId + BrowseWorkbooksUseCaseIn(category ?: WorkBookCategory.All, viewCategory, 1L).let { useCaseIn -> browseWorkBooksUseCase.execute(useCaseIn) } 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 7450ab8a8..2d93b4ace 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 @@ -1,10 +1,18 @@ package com.few.api.domain.workbook.usecase import com.few.api.domain.workbook.service.WorkbookMemberService +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.BrowseWorkBookDetail import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn +import com.few.api.domain.workbook.usecase.dto.WriterDetail +import com.few.api.domain.workbook.usecase.model.AuthMainViewWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.model.BasicWorkbookOrderDelegator +import com.few.api.domain.workbook.usecase.service.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 import com.few.api.web.support.WorkBookCategory import io.kotest.core.spec.style.BehaviorSpec import io.mockk.every @@ -17,12 +25,17 @@ import java.time.LocalDateTime 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() - useCase = BrowseWorkbooksUseCase(workbookDao, workbookMemberService) + workbookSubscribeService = mockk() + workbookOrderDelegatorExecutor = mockk() + useCase = + BrowseWorkbooksUseCase(workbookDao, workbookMemberService, workbookSubscribeService, workbookOrderDelegatorExecutor) } given("다수 워크북 조회 요청이 온 상황에서") { @@ -67,12 +80,198 @@ class BrowseWorkbooksUseCaseTest : BehaviorSpec({ ) ) + every { + workbookOrderDelegatorExecutor.execute(any()) + } returns listOf( + BrowseWorkBookDetail( + id = 1L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = WorkBookCategory.ECONOMY.displayName, + description = "workbook description", + createdAt = LocalDateTime.now(), + writerDetails = listOf( + WriterDetail( + id = 1L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/") + ) + ), + subscriptionCount = 10 + ) + ) + + then("지정한 카테고리의 워크북이 조회된다") { + val useCaseIn = BrowseWorkbooksUseCaseIn(category = WorkBookCategory.ECONOMY, viewCategory = null, memberId = null) + useCase.execute(useCaseIn) + + verify(exactly = 1) { workbookDao.browseWorkBookWithSubscriptionCount(any()) } + verify(exactly = 1) { workbookMemberService.browseWorkbookWriterRecords(any()) } + verify(exactly = 0) { workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) } + verify(exactly = 1) { workbookOrderDelegatorExecutor.execute(any()) } + } + } + } + + given("메인에서 다수 워크북 조회 요청이 온 상황에서") { + `when`("로그인이 되어 있을 경우") { + every { workbookDao.browseWorkBookWithSubscriptionCount(any()) } returns listOf( + SelectWorkBookRecordWithSubscriptionCount( + id = 1L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = (10).toByte(), + description = "workbook description", + createdAt = LocalDateTime.now(), + subscriptionCount = 10 + ), + SelectWorkBookRecordWithSubscriptionCount( + id = 2L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = (10).toByte(), + description = "workbook description", + createdAt = LocalDateTime.now(), + subscriptionCount = 10 + ) + ) + + every { workbookMemberService.browseWorkbookWriterRecords(any()) } returns mapOf( + 1L to listOf( + WriterMappedWorkbookOutDto( + writerId = 1L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/"), + workbookId = 1L + ) + ), + 2L to listOf( + WriterMappedWorkbookOutDto( + writerId = 2L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/"), + workbookId = 2L + ) + ) + ) + + every { + workbookSubscribeService.browseMemberSubscribeWorkbooks(any()) + } returns listOf( + BrowseMemberSubscribeWorkbooksOutDto( + workbookId = 1L, + isActiveSub = true, + currentDay = 1 + ), + BrowseMemberSubscribeWorkbooksOutDto( + workbookId = 2L, + isActiveSub = false, + currentDay = 1 + ) + ) + + every { + workbookOrderDelegatorExecutor.execute(any(AuthMainViewWorkbookOrderDelegator::class)) + } returns listOf( + BrowseWorkBookDetail( + id = 1L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = WorkBookCategory.ECONOMY.displayName, + description = "workbook description", + createdAt = LocalDateTime.now(), + writerDetails = listOf( + WriterDetail( + id = 1L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/") + ) + ), + subscriptionCount = 10 + ) + ) + + then("인증 메인뷰 워크북 정렬이 실행된 결과가 반환된다") { + val useCaseIn = BrowseWorkbooksUseCaseIn(category = WorkBookCategory.ECONOMY, viewCategory = ViewCategory.MAIN_CARD, memberId = 1L) + useCase.execute(useCaseIn) + + 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)) } + } + } + + `when`("로그인이 되어 있지 않은 경우") { + every { workbookDao.browseWorkBookWithSubscriptionCount(any()) } returns listOf( + SelectWorkBookRecordWithSubscriptionCount( + id = 1L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = (10).toByte(), + description = "workbook description", + createdAt = LocalDateTime.now(), + subscriptionCount = 10 + ), + SelectWorkBookRecordWithSubscriptionCount( + id = 2L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = (10).toByte(), + description = "workbook description", + createdAt = LocalDateTime.now(), + subscriptionCount = 10 + ) + ) + + every { workbookMemberService.browseWorkbookWriterRecords(any()) } returns mapOf( + 1L to listOf( + WriterMappedWorkbookOutDto( + writerId = 1L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/"), + workbookId = 1L + ) + ), + 2L to listOf( + WriterMappedWorkbookOutDto( + writerId = 2L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/"), + workbookId = 2L + ) + ) + ) + + every { + workbookOrderDelegatorExecutor.execute(any(BasicWorkbookOrderDelegator::class)) + } returns listOf( + BrowseWorkBookDetail( + id = 1L, + title = "workbook title", + mainImageUrl = URL("https://jh-labs.tistory.com/"), + category = WorkBookCategory.ECONOMY.displayName, + description = "workbook description", + createdAt = LocalDateTime.now(), + writerDetails = listOf( + WriterDetail( + id = 1L, + name = "hunca", + url = URL("https://jh-labs.tistory.com/") + ) + ), + subscriptionCount = 10 + ) + ) + then("지정한 카테고리의 워크북이 조회된다") { - val useCaseIn = BrowseWorkbooksUseCaseIn(category = WorkBookCategory.All) + val useCaseIn = BrowseWorkbooksUseCaseIn(category = WorkBookCategory.ECONOMY, viewCategory = ViewCategory.MAIN_CARD, memberId = null) useCase.execute(useCaseIn) 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/web/controller/workbook/WorkBookControllerTest.kt b/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt index b454b0771..afc644c52 100644 --- a/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt +++ b/api/src/test/kotlin/com/few/api/web/controller/workbook/WorkBookControllerTest.kt @@ -12,6 +12,7 @@ import com.few.api.domain.workbook.usecase.dto.* import com.few.api.web.controller.ControllerTestSpec import com.few.api.web.controller.description.Description import com.few.api.web.controller.helper.* +import com.few.api.web.support.ViewCategory import com.few.api.web.support.WorkBookCategory import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get import com.few.data.common.code.CategoryType @@ -121,14 +122,17 @@ class WorkBookControllerTest : ControllerTestSpec() { fun browseWorkBooks() { // given val api = "BrowseWorkBooks" + val viewCategory = ViewCategory.MAIN_CARD + val memberId = 1L val uri = UriComponentsBuilder.newInstance() .path(BASE_URL) .queryParam("category", WorkBookCategory.ECONOMY.code) + .queryParam("view", viewCategory.viewName) .build() .toUriString() // set usecase mock - `when`(browseWorkBooksUseCase.execute(BrowseWorkbooksUseCaseIn(WorkBookCategory.ECONOMY))).thenReturn( + `when`(browseWorkBooksUseCase.execute(BrowseWorkbooksUseCaseIn(WorkBookCategory.ECONOMY, viewCategory, memberId))).thenReturn( BrowseWorkbooksUseCaseOut( workbooks = listOf( BrowseWorkBookDetail( @@ -165,7 +169,8 @@ class WorkBookControllerTest : ControllerTestSpec() { .tag(TAG) .requestSchema(Schema.schema(api.toRequestSchema())) .queryParameters( - parameterWithName("category").description("학습지 카테고리").optional() + parameterWithName("category").description("학습지 카테고리").optional(), + parameterWithName("view").description("뷰 카테고리").optional() ) .responseSchema(Schema.schema(api.toResponseSchema())).responseFields( *Description.describe(