Skip to content

Commit

Permalink
feat: mainViewBrowseSubscribeWorkbooks 구현 (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 authored Aug 3, 2024
1 parent 44332ef commit 2ea547e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -64,6 +72,50 @@ class SubscriptionController(
}
}

// 임시 구현
@GetMapping("/subscriptions/workbooks/main")
fun mainViewBrowseSubscribeWorkbooks(
@RequestParam(value = "category", required = false)
category: WorkBookCategory?,
): ApiResponse<ApiResponse.SuccessBody<MainViewBrowseSubscribeWorkbooksResponse>> {
// 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MainViewSubscribeWorkbookInfo>,
)

@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<WriterDetail>,
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
)

0 comments on commit 2ea547e

Please sign in to comment.