Skip to content

Commit

Permalink
[Feat/#331] My 구독관리 API 추가 (#376)
Browse files Browse the repository at this point in the history
* feat: 구독 관리를 위한 send_time, send_day 컬럼 추가

* feat: workbook 제목 조회 쿼리 추가

* feat: 구독 전송 상태 조회 쿼리 추가

* feat: selectAllWorkbookInActiveSubscriptionStatusQuery progress에 따른 정렬 조건 추가

* feat: workbook 제목 조회 서비스 구현

* refactor: SUBSCRIBE_WORKBOOK_STRATEGY에 따라 workbook 구독 정보 조회할 수 있도록 수정

* feat: DayCode webConfig에 등록

* feat: myPage ViewCategory 추가

* refactor: /subscriptions/workbooks view에 따른 구분 및 /subscriptions/workbooks/main 삭제
  • Loading branch information
belljun3395 authored Sep 6, 2024
1 parent 48aed88 commit be5d051
Show file tree
Hide file tree
Showing 24 changed files with 779 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.few.api.repo.dao.subscription.query.*
import com.few.api.repo.dao.subscription.record.WorkbookSubscriptionStatus
import com.few.api.repo.dao.subscription.record.CountAllSubscriptionStatusRecord
import com.few.api.repo.dao.subscription.record.MemberWorkbookSubscriptionStatusRecord
import com.few.api.repo.dao.subscription.record.SubscriptionSendStatusRecord
import jooq.jooq_dsl.Tables.MAPPING_WORKBOOK_ARTICLE
import jooq.jooq_dsl.Tables.SUBSCRIPTION
import jooq.jooq_dsl.tables.MappingWorkbookArticle
Expand Down Expand Up @@ -79,8 +80,10 @@ class SubscriptionDao(
dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(MemberWorkbookSubscriptionStatusRecord::workbookId.name),
SUBSCRIPTION.DELETED_AT.isNull.`as`(MemberWorkbookSubscriptionStatusRecord::isActiveSub.name),
DSL.max(SUBSCRIPTION.PROGRESS).add(1).`as`(MemberWorkbookSubscriptionStatusRecord::currentDay.name),
DSL.max(MAPPING_WORKBOOK_ARTICLE.DAY_COL).`as`(MemberWorkbookSubscriptionStatusRecord::totalDay.name)
DSL.max(SUBSCRIPTION.PROGRESS).add(1)
.`as`(MemberWorkbookSubscriptionStatusRecord::currentDay.name),
DSL.max(MAPPING_WORKBOOK_ARTICLE.DAY_COL)
.`as`(MemberWorkbookSubscriptionStatusRecord::totalDay.name)
)
.from(SUBSCRIPTION)
.join(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE)
Expand All @@ -89,6 +92,7 @@ class SubscriptionDao(
.and(SUBSCRIPTION.TARGET_MEMBER_ID.isNull)
.and(SUBSCRIPTION.UNSUBS_OPINION.eq(query.unsubOpinion))
.groupBy(SUBSCRIPTION.TARGET_WORKBOOK_ID, SUBSCRIPTION.DELETED_AT)
.orderBy(SUBSCRIPTION.PROGRESS)
.query

fun selectAllActiveWorkbookSubscriptionStatus(query: SelectAllMemberWorkbookActiveSubscriptionQuery): List<MemberWorkbookSubscriptionStatusRecord> {
Expand All @@ -110,6 +114,7 @@ class SubscriptionDao(
.and(SUBSCRIPTION.TARGET_MEMBER_ID.isNull)
.and(SUBSCRIPTION.UNSUBS_OPINION.isNull)
.groupBy(SUBSCRIPTION.TARGET_WORKBOOK_ID, SUBSCRIPTION.DELETED_AT)
.orderBy(SUBSCRIPTION.PROGRESS)
.query

fun updateDeletedAtInAllSubscription(command: UpdateDeletedAtInAllSubscriptionCommand) {
Expand Down Expand Up @@ -185,4 +190,21 @@ class SubscriptionDao(
.set(SUBSCRIPTION.UNSUBS_OPINION, command.opinion)
.where(SUBSCRIPTION.MEMBER_ID.eq(command.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(command.workbookId))

fun selectAllSubscriptionSendStatus(query: SelectAllSubscriptionSendStatusQuery): List<SubscriptionSendStatusRecord> {
return selectAllSubscriptionSendStatusQuery(query)
.fetchInto(
SubscriptionSendStatusRecord::class.java
)
}

fun selectAllSubscriptionSendStatusQuery(query: SelectAllSubscriptionSendStatusQuery) =
dslContext.select(
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(SubscriptionSendStatusRecord::workbookId.name),
SUBSCRIPTION.SEND_TIME.`as`(SubscriptionSendStatusRecord::sendTime.name),
SUBSCRIPTION.SEND_DAY.`as`(SubscriptionSendStatusRecord::sendDay.name)
)
.from(SUBSCRIPTION)
.where(SUBSCRIPTION.MEMBER_ID.eq(query.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.`in`(query.workbookIds))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.subscription.query

data class SelectAllSubscriptionSendStatusQuery(
val memberId: Long,
val workbookIds: List<Long>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.few.api.repo.dao.subscription.record

import java.time.LocalTime

data class SubscriptionSendStatusRecord(
val workbookId: Long,
val sendTime: LocalTime,
val sendDay: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM
import com.few.api.repo.dao.workbook.command.InsertWorkBookCommand
import com.few.api.repo.dao.workbook.command.MapWorkBookToArticleCommand
import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery
import com.few.api.repo.dao.workbook.query.SelectAllWorkbookTitleQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecord
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount
import com.few.api.repo.dao.workbook.record.WorkbookTitleRecord
import com.few.data.common.code.CategoryType
import jooq.jooq_dsl.tables.MappingWorkbookArticle
import jooq.jooq_dsl.tables.Subscription
Expand Down Expand Up @@ -144,4 +146,17 @@ class WorkbookDao(
.where(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID.eq(query.workbookId))
.and(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.DELETED_AT.isNull)
.groupBy(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID)

fun selectAllWorkbookTitle(query: SelectAllWorkbookTitleQuery): List<WorkbookTitleRecord> {
return selectAllWorkbookTitleQuery(query)
.fetchInto(WorkbookTitleRecord::class.java)
}

fun selectAllWorkbookTitleQuery(query: SelectAllWorkbookTitleQuery) =
dslContext.select(
Workbook.WORKBOOK.ID.`as`(WorkbookTitleRecord::workbookId.name),
Workbook.WORKBOOK.TITLE.`as`(WorkbookTitleRecord::title.name)
)
.from(Workbook.WORKBOOK)
.where(Workbook.WORKBOOK.ID.`in`(query.workbookIds))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.workbook.query

data class SelectAllWorkbookTitleQuery(
val workbookIds: List<Long>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.workbook.record

data class WorkbookTitleRecord(
val workbookId: Long,
val title: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.few.api.repo.explain.subscription

import com.few.api.repo.dao.subscription.SubscriptionDao
import com.few.api.repo.dao.subscription.command.*
import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscriptionQuery
import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookInActiveSubscriptionQuery
import com.few.api.repo.dao.subscription.query.*
import com.few.api.repo.explain.ExplainGenerator
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
Expand Down Expand Up @@ -190,4 +187,18 @@ class SubscriptionDaoExplainGenerateTest : JooqTestSpec() {

ResultGenerator.execute(command, explain, "updateLastArticleProgressCommandExplain")
}

@Test
fun selectAllSubscriptionSendStatusQueryExplain() {
val query = subscriptionDao.selectAllSubscriptionSendStatusQuery(
SelectAllSubscriptionSendStatusQuery(
memberId = 1L,
workbookIds = listOf(1L)
)
)

val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectAllSubscriptionSendStatusQueryExplain")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.few.api.repo.dao.workbook.WorkbookDao
import com.few.api.repo.dao.workbook.command.InsertWorkBookCommand
import com.few.api.repo.dao.workbook.command.MapWorkBookToArticleCommand
import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCountQuery
import com.few.api.repo.dao.workbook.query.SelectAllWorkbookTitleQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.explain.ExplainGenerator
Expand Down Expand Up @@ -118,4 +119,17 @@ class WorkbookDaoExplainGenerateTest : JooqTestSpec() {

ResultGenerator.execute(query, explain, "selectWorkBookLastArticleIdQueryExplain")
}

@Test
fun selectAllWorkbookTitleQueryExplain() {
val query = workbookDao.selectAllWorkbookTitleQuery(
SelectAllWorkbookTitleQuery(
listOf(1L)
)
)

val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectAllWorkbookTitleQueryExplain")
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.few.api.domain.subscription.service

import com.few.api.domain.subscription.service.dto.ReadWorkbookLastArticleIdInDto
import com.few.api.domain.subscription.service.dto.ReadWorkbookLastArticleIdOutDto
import com.few.api.domain.subscription.service.dto.ReadWorkbookTitleInDto
import com.few.api.domain.subscription.service.dto.ReadWorkbookTitleOutDto
import com.few.api.domain.subscription.service.dto.*
import com.few.api.repo.dao.workbook.WorkbookDao
import com.few.api.repo.dao.workbook.query.SelectAllWorkbookTitleQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import org.springframework.stereotype.Service
Expand All @@ -24,6 +22,15 @@ class SubscriptionWorkbookService(
}
}

/**
* key: workbookId
* value: title
*/
fun readAllWorkbookTitle(dto: ReadAllWorkbookTitleInDto): Map<Long, String> {
return workbookDao.selectAllWorkbookTitle(SelectAllWorkbookTitleQuery(dto.workbookIds))
.associateBy({ it.workbookId }, { it.title })
}

fun readWorkbookLastArticleId(dto: ReadWorkbookLastArticleIdInDto): ReadWorkbookLastArticleIdOutDto? {
return workbookDao.selectWorkBookLastArticleId(SelectWorkBookLastArticleIdQuery(dto.workbookId))
?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.domain.subscription.service.dto

data class ReadAllWorkbookTitleInDto(
val workbookIds: List<Long>,
)
Loading

0 comments on commit be5d051

Please sign in to comment.