Skip to content

Commit

Permalink
[RELEASE] v24.08.12.01 YAPP-Github#342
Browse files Browse the repository at this point in the history
* [Refactor/YAPP-Github#329] 테스트 코드 보강 및 개선 (YAPP-Github#330)

* [Fix/YAPP-Github#338] 구독 학습지 마지막 아티클을 받고 progess를 증가하는 문제해결 (YAPP-Github#339)
  • Loading branch information
belljun3395 authored Aug 11, 2024
2 parents 1f7ffaa + 71a2094 commit 3f589e9
Show file tree
Hide file tree
Showing 50 changed files with 1,672 additions and 893 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArticleMainCardDao(
.toSet()
}

private fun selectArticleMainCardsRecordQuery(articleIds: Set<Long>) = dslContext.select(
fun selectArticleMainCardsRecordQuery(articleIds: Set<Long>) = dslContext.select(
ARTICLE_MAIN_CARD.ID.`as`(ArticleMainCardRecord::articleId.name),
ARTICLE_MAIN_CARD.TITLE.`as`(ArticleMainCardRecord::articleTitle.name),
ARTICLE_MAIN_CARD.MAIN_IMAGE_URL.`as`(ArticleMainCardRecord::mainImageUrl.name),
Expand All @@ -46,9 +46,9 @@ class ArticleMainCardDao(
* NOTE - The query performed in this function do not save the workbook.
*/
fun insertArticleMainCard(command: ArticleMainCardExcludeWorkbookCommand) =
insertArticleMainCardQuery(command).execute()
insertArticleMainCardCommand(command).execute()

fun insertArticleMainCardQuery(command: ArticleMainCardExcludeWorkbookCommand) = dslContext
fun insertArticleMainCardCommand(command: ArticleMainCardExcludeWorkbookCommand) = dslContext
.insertInto(
ARTICLE_MAIN_CARD,
ARTICLE_MAIN_CARD.ID,
Expand Down Expand Up @@ -79,9 +79,9 @@ class ArticleMainCardDao(
)

fun updateArticleMainCardSetWorkbook(command: UpdateArticleMainCardWorkbookCommand) =
updateArticleMainCardSetWorkbookQuery(command).execute()
updateArticleMainCardSetWorkbookCommand(command).execute()

fun updateArticleMainCardSetWorkbookQuery(command: UpdateArticleMainCardWorkbookCommand) = dslContext
fun updateArticleMainCardSetWorkbookCommand(command: UpdateArticleMainCardWorkbookCommand) = dslContext
.update(ARTICLE_MAIN_CARD)
.set(ARTICLE_MAIN_CARD.WORKBOOKS, JSON.valueOf(articleMainCardMapper.toJsonStr(command.workbooks)))
.where(ARTICLE_MAIN_CARD.ID.eq(command.articleId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@ class SubscriptionDao(
.set(SUBSCRIPTION.TARGET_WORKBOOK_ID, command.workbookId)

fun reSubscribeWorkbookSubscription(command: InsertWorkbookSubscriptionCommand) {
reSubscribeWorkBookSubscriptionCommand(command)
.execute()
}

fun reSubscribeWorkBookSubscriptionCommand(command: InsertWorkbookSubscriptionCommand) =
dslContext.update(SUBSCRIPTION)
.set(SUBSCRIPTION.DELETED_AT, null as LocalDateTime?)
.set(SUBSCRIPTION.UNSUBS_OPINION, null as String?)
.where(SUBSCRIPTION.MEMBER_ID.eq(command.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(command.workbookId))

fun updateDeletedAtInWorkbookSubscription(command: UpdateDeletedAtInWorkbookSubscriptionCommand) {
updateDeletedAtInWorkbookSubscriptionCommand(command)
.execute()
}

fun updateDeletedAtInWorkbookSubscription(command: UpdateDeletedAtInWorkbookSubscriptionCommand) {
fun updateDeletedAtInWorkbookSubscriptionCommand(command: UpdateDeletedAtInWorkbookSubscriptionCommand) =
dslContext.update(SUBSCRIPTION)
.set(SUBSCRIPTION.DELETED_AT, LocalDateTime.now())
.set(SUBSCRIPTION.UNSUBS_OPINION, command.opinion)
.where(SUBSCRIPTION.MEMBER_ID.eq(command.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(command.workbookId))
.execute()
}

fun selectTopWorkbookSubscriptionStatus(query: SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery): WorkbookSubscriptionStatus? {
return selectTopWorkbookSubscriptionStatusQuery(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ class WorkbookDao(
.set(Workbook.WORKBOOK.DESCRIPTION, command.description)

fun mapWorkBookToArticle(command: MapWorkBookToArticleCommand) {
mapWorkBookToArticleCommand(command)
.execute()
}

fun mapWorkBookToArticleCommand(command: MapWorkBookToArticleCommand) =
dslContext.insertInto(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE)
.set(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID, command.workbookId)
.set(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.ARTICLE_ID, command.articleId)
.set(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.DAY_COL, command.dayCol)
.execute()
}

/**
* category에 따라서 조회된 구독자 수가 포함된 Workbook 목록을 반환한다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,15 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {

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

@Test
fun selectArticleContentsQueryExplain() {
val query = setOf(1L).let {
articleDao.selectArticleContentsQuery(it)
}

val explain = dslContext.explain(query).toString()

ResultGenerator.execute(query, explain, "selectArticleContentsQueryExplain")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.few.api.repo.explain.article

import com.few.api.repo.dao.article.ArticleMainCardDao
import com.few.api.repo.dao.article.command.ArticleMainCardExcludeWorkbookCommand
import com.few.api.repo.dao.article.command.UpdateArticleMainCardWorkbookCommand
import com.few.api.repo.dao.article.command.WorkbookCommand
import com.few.api.repo.explain.ResultGenerator
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.CategoryType
import io.github.oshai.kotlinlogging.KotlinLogging
import jooq.jooq_dsl.tables.ArticleMainCard
import org.jooq.DSLContext
import org.jooq.JSON
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import java.net.URL
import java.time.LocalDateTime

@Tag("explain")
class ArticleMainCardDaoExplainGenerateTest : JooqTestSpec() {
private val log = KotlinLogging.logger {}

@Autowired
private lateinit var dslContext: DSLContext

@Autowired
private lateinit var articleMainCardDao: ArticleMainCardDao

@BeforeEach
fun setUp() {
log.debug { "===== start setUp =====" }
dslContext.deleteFrom(ArticleMainCard.ARTICLE_MAIN_CARD).execute()
dslContext.insertInto(ArticleMainCard.ARTICLE_MAIN_CARD)
.set(ArticleMainCard.ARTICLE_MAIN_CARD.ID, 1L)
.set(ArticleMainCard.ARTICLE_MAIN_CARD.TITLE, "this is title1")
.set(
ArticleMainCard.ARTICLE_MAIN_CARD.MAIN_IMAGE_URL,
"http://localhost:8080/image1.jpg"
)
.set(ArticleMainCard.ARTICLE_MAIN_CARD.CATEGORY_CD, CategoryType.fromCode(0)!!.code)
.set(ArticleMainCard.ARTICLE_MAIN_CARD.CREATED_AT, LocalDateTime.now())
.set(ArticleMainCard.ARTICLE_MAIN_CARD.WRITER_ID, 1L)
.set(ArticleMainCard.ARTICLE_MAIN_CARD.WRITER_EMAIL, "[email protected]")
.set(
ArticleMainCard.ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
JSON.valueOf("{ \"name\": \"writer\", \"url\": \"http://localhost:8080/writer\", \"imgUrl\": \"http://localhost:8080/writer.jpg\" }")
)
.set(
ArticleMainCard.ARTICLE_MAIN_CARD.WORKBOOKS,
JSON.valueOf("[{\"id\": 1, \"title\": \"title\"}]")
)
.execute()
log.debug { "===== finish setUp =====" }
}

@Test
fun selectArticleMainCardsRecordQueryExplain() {
val query = articleMainCardDao.selectArticleMainCardsRecordQuery(setOf(1L))

val explain = dslContext.explain(query).toString()
ResultGenerator.execute(query, explain, "selectArticleMainCardsRecordQueryExplain")
}

@Test
fun insertArticleMainCardCommandExplain() {
val command = ArticleMainCardExcludeWorkbookCommand(
articleId = 2L,
articleTitle = "this is title2",
mainImageUrl = URL("http://localhost:8080/image2.jpg"),
categoryCd = CategoryType.fromCode(0)!!.code,
createdAt = LocalDateTime.now(),
writerId = 1L,
writerEmail = "[email protected]",
writerName = "writer",
writerUrl = URL("http://localhost:8080/writer"),
writerImgUrl = URL("http://localhost:8080/writer.jpg")
).let {
articleMainCardDao.insertArticleMainCardCommand(it)
}

val explain = command.toString()

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

@Test
fun updateArticleMainCardSetWorkbookCommandExplain() {
val command = UpdateArticleMainCardWorkbookCommand(
articleId = 1L,
workbooks = listOf(
WorkbookCommand(
id = 1L,
title = "workbook1"
),
WorkbookCommand(
id = 2L,
title = "workbook2"
)
)
).let {
articleMainCardDao.updateArticleMainCardSetWorkbookCommand(it)
}

val explain = command.toString()

ResultGenerator.execute(command, explain, "updateArticleMainCardSetWorkbookCommandExplain")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.few.api.repo.explain.article
import com.few.api.repo.dao.article.ArticleViewCountDao
import com.few.api.repo.dao.article.command.ArticleViewCountCommand
import com.few.api.repo.dao.article.query.ArticleViewCountQuery
import com.few.api.repo.dao.article.query.SelectArticlesOrderByViewsQuery
import com.few.api.repo.dao.article.query.SelectRankByViewsQuery
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
import com.few.api.repo.jooq.JooqTestSpec
Expand Down Expand Up @@ -61,4 +63,41 @@ class ArticleViewCountDaoExplainGenerateTest : JooqTestSpec() {

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

@Test
fun insertArticleViewCountToZeroQueryExplain() {
val command = ArticleViewCountQuery(
articleId = 1L,
categoryType = CategoryType.fromCode(0)!!
).let {
articleViewCountDao.insertArticleViewCountToZeroQuery(it)
}

val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

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

@Test
fun selectRankByViewsQueryExplain() {
val query = SelectRankByViewsQuery(1L).let {
articleViewCountDao.selectRankByViewsQuery(it)
}

val explain = dslContext.explain(query).toString()
ResultGenerator.execute(query, explain, "selectRankByViewsQueryExplain")
}

@Test
fun selectArticlesOrderByViewsQueryExplain() {
val query = SelectArticlesOrderByViewsQuery(
offset = 0,
category = CategoryType.fromCode(0)!!
).let {
articleViewCountDao.selectArticlesOrderByViewsQuery(it)
}

val explain = dslContext.explain(query).toString()
ResultGenerator.execute(query, explain, "selectArticlesOrderByViewsQueryExplain")
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.few.api.repo.explain.member

import com.few.api.repo.dao.member.MemberDao
import com.few.api.repo.dao.member.command.DeleteMemberCommand
import com.few.api.repo.dao.member.command.InsertMemberCommand
import com.few.api.repo.dao.member.command.UpdateDeletedMemberTypeCommand
import com.few.api.repo.dao.member.command.UpdateMemberTypeCommand
import com.few.api.repo.dao.member.query.BrowseWorkbookWritersQuery
import com.few.api.repo.dao.member.query.SelectMemberByEmailNotConsiderDeletedAtQuery
import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery
import com.few.api.repo.dao.member.query.SelectWriterQuery
import com.few.api.repo.dao.member.support.WriterDescription
Expand Down Expand Up @@ -117,7 +119,7 @@ class MemberDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun selectMemberByEmailNotConsiderDeletedAtQueryExplain() {
val query = SelectMemberByEmailQuery("[email protected]").let {
val query = SelectMemberByEmailNotConsiderDeletedAtQuery("[email protected]").let {
memberDao.selectMemberByEmailQuery(it)
}

Expand Down Expand Up @@ -181,11 +183,10 @@ class MemberDaoExplainGenerateTest : JooqTestSpec() {

@Test
fun deleteMemberCommandExplain() {
val command = UpdateDeletedMemberTypeCommand(
id = 1,
memberType = MemberType.WRITER
val command = DeleteMemberCommand(
memberId = 1
).let {
memberDao.updateMemberTypeCommand(it)
memberDao.deleteMemberCommand(it)
}

val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.few.api.repo.explain.subscription
import com.few.api.repo.dao.subscription.SubscriptionDao
import com.few.api.repo.dao.subscription.command.InsertWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInAllSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.query.CountWorkbookMappedArticlesQuery
import com.few.api.repo.dao.subscription.query.SelectAllMemberWorkbookActiveSubscription
import com.few.api.repo.dao.subscription.query.SelectAllWorkbookSubscriptionStatusNotConsiderDeletedAtQuery
Expand Down Expand Up @@ -137,4 +138,33 @@ class SubscriptionDaoExplainGenerateTest : JooqTestSpec() {

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

@Test
fun reSubscribeWorkBookSubscriptionCommandExplain() {
val command = InsertWorkbookSubscriptionCommand(
memberId = 1L,
workbookId = 1L
).let {
subscriptionDao.reSubscribeWorkBookSubscriptionCommand(it)
}

val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

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

@Test
fun updateDeletedAtInWorkbookSubscriptionCommandExplain() {
val command = UpdateDeletedAtInWorkbookSubscriptionCommand(
memberId = 1L,
workbookId = 1L,
opinion = "test"
).let {
subscriptionDao.updateDeletedAtInWorkbookSubscriptionCommand(it)
}

val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

ResultGenerator.execute(command, explain, "updateDeletedAtInWorkbookSubscriptionCommandExplain")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.few.api.repo.explain.workbook

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.BrowseWorkBookQueryWithSubscriptionCount
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.explain.InsertUpdateExplainGenerator
Expand Down Expand Up @@ -89,4 +90,19 @@ class WorkbookDaoExplainGenerateTest : JooqTestSpec() {

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

@Test
fun mapWorkBookToArticleCommandExplain() {
val command = MapWorkBookToArticleCommand(
workbookId = 1L,
articleId = 1L,
dayCol = 1
).let {
workbookDao.mapWorkBookToArticleCommand(it)
}

val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

ResultGenerator.execute(command, explain, "mapWorkBookToArticleCommandExplain")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TokenUseCase(

@Transactional
fun execute(useCaseIn: TokenUseCaseIn): TokenUseCaseOut {
var isLogin = true

/** refreshToken이 요청에 포함되어 있으면 refreshToken을 통해 memberId를 추출하여 새로운 토큰을 발급 */
var _memberId: Long? = null
var _memberEmail: String? = null
Expand Down Expand Up @@ -59,6 +61,7 @@ class TokenUseCase(
?: throw NotFoundException("member.notfound.id")

if (memberEmailAndTypeRecord.memberType == MemberType.PREAUTH) {
isLogin = false
UpdateMemberTypeCommand(
id = memberId,
memberType = MemberType.NORMAL
Expand All @@ -79,7 +82,7 @@ class TokenUseCase(
return TokenUseCaseOut(
accessToken = token.accessToken,
refreshToken = token.refreshToken,
isLogin = false
isLogin = isLogin
)
}
}
Loading

0 comments on commit 3f589e9

Please sign in to comment.