Skip to content

Commit

Permalink
test: join 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jan 15, 2025
1 parent 05dcb45 commit 96f3da0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.few.api.repo.dao.article.command.UpdateArticleMainCardWorkbookCommand
import com.few.api.repo.dao.article.record.ArticleMainCardRecord
import com.few.api.repo.dao.article.support.CommonJsonMapper
import com.few.api.repo.dao.article.support.ArticleMainCardMapper
import jooq.jooq_dsl.tables.ArticleIfo
import jooq.jooq_dsl.tables.ArticleIfo.ARTICLE_IFO
import jooq.jooq_dsl.tables.ArticleMainCard.ARTICLE_MAIN_CARD
import org.jooq.*
import org.jooq.impl.DSL.*
Expand Down Expand Up @@ -38,8 +40,11 @@ class ArticleMainCardDao(
).`as`(ArticleMainCardRecord::writerName.name),
jsonGetAttribute(ARTICLE_MAIN_CARD.WRITER_DESCRIPTION, "url").`as`(ArticleMainCardRecord::writerUrl.name),
jsonGetAttribute(ARTICLE_MAIN_CARD.WRITER_DESCRIPTION, "imageUrl").`as`(ArticleMainCardRecord::writerImgUrl.name),
ARTICLE_MAIN_CARD.WORKBOOKS.`as`(ArticleMainCardRecord::workbooks.name)
ARTICLE_MAIN_CARD.WORKBOOKS.`as`(ArticleMainCardRecord::workbooks.name),
ARTICLE_IFO.CONTENT.`as`(ArticleMainCardRecord::content.name)
).from(ARTICLE_MAIN_CARD)
.join(ARTICLE_IFO)
.on(ARTICLE_MAIN_CARD.ID.eq(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID))
.where(ARTICLE_MAIN_CARD.ID.`in`(articleIds))
.query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ data class ArticleMainCardRecord(
val writerUrl: URL,
val writerImgUrl: URL,
val workbooks: List<WorkbookRecord> = emptyList(),
val content: String = "",
) {
var content: String = ""
set(value) {
field = value
}

var views: Long = 0L
set(value) {
field = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class ArticleMainCardMapper(
}
} ?: run {
emptyList()
}
},
content = record.get(ArticleMainCardRecord::content.name, String::class.java)
)

fun toJsonStr(workbooks: List<WorkbookCommand>) = objectMapper.writeValueAsString(workbooks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.few.api.exception.common.NotFoundException
import com.few.api.repo.dao.article.ArticleDao
import com.few.api.repo.dao.article.ArticleMainCardDao
import com.few.api.repo.dao.article.record.ArticleMainCardRecord
import com.few.api.repo.dao.article.record.SelectArticleContentsRecord
import com.few.data.common.code.CategoryType
import org.springframework.stereotype.Component
import java.util.*
Expand All @@ -24,12 +23,6 @@ class BrowseArticlesUseCase(

val articleIds = limitedArticleViewsRecords.map { it.articleId }.toSet()
val articleMainCardRecords: List<ArticleMainCardRecord> = articleMainCardDao.selectArticleMainCardsRecord(articleIds)
val selectArticleContentsRecords: List<SelectArticleContentsRecord> = articleDao.selectArticleContents(articleIds)

val contentsMap = selectArticleContentsRecords.associateBy { it.articleId }
articleMainCardRecords.forEach { record ->
record.content = contentsMap[record.articleId]?.content ?: ""
}

val articleUseCaseOuts: List<ReadArticleUseCaseOut> =
articleMainCardRecords
Expand Down

0 comments on commit 96f3da0

Please sign in to comment.