From 2ea547ea08203d4b504c32f32ecd80d60dce1af8 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Sun, 4 Aug 2024 00:09:25 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20mainViewBrowseSubscribeWorkbooks=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#289)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subscription/SubscriptionController.kt | 52 +++++++++++++++++++ ...ainViewBrowseSubscribeWorkbooksResponse.kt | 30 +++++++++++ 2 files changed, 82 insertions(+) create mode 100644 api/src/main/kotlin/com/few/api/web/controller/subscription/response/MainViewBrowseSubscribeWorkbooksResponse.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 54933314e..7aac2e1b1 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 @@ -12,10 +12,15 @@ import com.few.api.domain.subscription.usecase.dto.BrowseSubscribeWorkbooksUseCa import com.few.api.domain.subscription.usecase.dto.SubscribeWorkbookUseCaseIn import com.few.api.domain.subscription.usecase.dto.UnsubscribeAllUseCaseIn import com.few.api.domain.subscription.usecase.dto.UnsubscribeWorkbookUseCaseIn +import com.few.api.domain.workbook.usecase.BrowseWorkbooksUseCase +import com.few.api.domain.workbook.usecase.dto.BrowseWorkbooksUseCaseIn import com.few.api.web.controller.subscription.request.UnsubscribeAllRequest +import com.few.api.web.controller.subscription.response.MainViewBrowseSubscribeWorkbooksResponse +import com.few.api.web.controller.subscription.response.MainViewSubscribeWorkbookInfo import com.few.api.web.controller.subscription.response.SubscribeWorkbookInfo import com.few.api.web.controller.subscription.response.SubscribeWorkbooksResponse import com.few.api.web.support.ViewCategory +import com.few.api.web.support.WorkBookCategory import jakarta.validation.Valid import jakarta.validation.constraints.Min import org.springframework.http.HttpStatus @@ -31,6 +36,9 @@ class SubscriptionController( private val unsubscribeWorkbookUseCase: UnsubscribeWorkbookUseCase, private val unsubscribeAllUseCase: UnsubscribeAllUseCase, private val browseSubscribeWorkbooksUseCase: BrowseSubscribeWorkbooksUseCase, + + // 임시 구현용 + private val browseWorkBooksUseCase: BrowseWorkbooksUseCase, ) { // todo add auth @@ -64,6 +72,50 @@ class SubscriptionController( } } + // 임시 구현 + @GetMapping("/subscriptions/workbooks/main") + fun mainViewBrowseSubscribeWorkbooks( + @RequestParam(value = "category", required = false) + category: WorkBookCategory?, + ): ApiResponse> { + // todo fix memberId + val memberId = 1L + val memberSubscribeWorkbooks = BrowseSubscribeWorkbooksUseCaseIn(memberId).let { + browseSubscribeWorkbooksUseCase.execute(it) + } + val workbooks = + BrowseWorkbooksUseCaseIn( + category ?: WorkBookCategory.All, + ViewCategory.MAIN_CARD, + memberId + ).let { useCaseIn -> + browseWorkBooksUseCase.execute(useCaseIn) + } + + return MainViewBrowseSubscribeWorkbooksResponse( + workbooks = workbooks.workbooks.map { + MainViewSubscribeWorkbookInfo( + id = it.id, + mainImageUrl = it.mainImageUrl, + title = it.title, + description = it.description, + category = it.category, + createdAt = it.createdAt, + writerDetails = it.writerDetails, + subscriptionCount = it.subscriptionCount, + status = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.isActiveSub?.name, + totalDay = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.totalDay, + currentDay = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.currentDay, + rank = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.rank, + totalSubscriber = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.totalSubscriber, + articleInfo = memberSubscribeWorkbooks.workbooks.find { subscribe -> subscribe.workbookId == it.id }?.articleInfo + ) + } + ).let { + ApiResponseGenerator.success(it, HttpStatus.OK) + } + } + @PostMapping("/workbooks/{workbookId}/subs") fun subscribeWorkbook( @PathVariable(value = "workbookId") diff --git a/api/src/main/kotlin/com/few/api/web/controller/subscription/response/MainViewBrowseSubscribeWorkbooksResponse.kt b/api/src/main/kotlin/com/few/api/web/controller/subscription/response/MainViewBrowseSubscribeWorkbooksResponse.kt new file mode 100644 index 000000000..ccf23008a --- /dev/null +++ b/api/src/main/kotlin/com/few/api/web/controller/subscription/response/MainViewBrowseSubscribeWorkbooksResponse.kt @@ -0,0 +1,30 @@ +package com.few.api.web.controller.subscription.response + +import com.fasterxml.jackson.annotation.JsonFormat +import com.fasterxml.jackson.annotation.JsonInclude +import com.few.api.domain.workbook.usecase.dto.WriterDetail +import java.net.URL +import java.time.LocalDateTime + +data class MainViewBrowseSubscribeWorkbooksResponse( + val workbooks: List, +) + +@JsonInclude(JsonInclude.Include.NON_NULL) +data class MainViewSubscribeWorkbookInfo( + val id: Long, + val mainImageUrl: URL, + val title: String, + val description: String, + val category: String, + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + val createdAt: LocalDateTime, + val writerDetails: List, + val subscriptionCount: Long, + val status: String?, // convert from enum + val totalDay: Int?, + val currentDay: Int?, + val rank: Long?, + val totalSubscriber: Long?, + val articleInfo: String?, // convert from Json +) \ No newline at end of file