Skip to content

Commit

Permalink
test: transactionResult 활용
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jan 15, 2025
1 parent e0c608a commit c54ee6b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
19 changes: 16 additions & 3 deletions api/src/main/kotlin/com/few/api/domain/article/repo/ArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,22 @@ class ArticleDao(
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)
.fetchOneInto(SelectArticleContentsRecord::class.java)

fun selectArticleContents(articleIds: Set<Long>): List<SelectArticleContentsRecord> =
selectArticleContentsQuery(articleIds)
.fetchInto(SelectArticleContentsRecord::class.java)
fun selectArticleContents(articleIds: Set<Long>): List<SelectArticleContentsRecord> {
return dslContext.transactionResult { configuration ->
val context = DSL.using(configuration)
return@transactionResult articleIds
.mapNotNull {
context
.select(
ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.`as`(SelectArticleContentsRecord::articleId.name),
ArticleIfo.ARTICLE_IFO.CONTENT.`as`(SelectArticleContentsRecord::content.name),
).from(ArticleIfo.ARTICLE_IFO)
.where(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.eq(it))
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)
.fetchOneInto(SelectArticleContentsRecord::class.java)
}.toList()
}
}

fun selectArticleContentsQuery(articleIds: Set<Long>) =
dslContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,40 @@ class ArticleMainCardDao(
.fetch(articleMainCardMapper)
.firstOrNull()

fun selectArticleMainCardsRecord(articleIds: Set<Long>): Set<ArticleMainCardRecord> =
selectArticleMainCardsRecordQuery(articleIds)
.fetch(articleMainCardMapper)
.toSet()
fun selectArticleMainCardsRecord(articleIds: Set<Long>): Set<ArticleMainCardRecord> {
return dslContext.transactionResult { configuration ->
val context = using(configuration)
return@transactionResult articleIds
.mapNotNull {
context
.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),
ARTICLE_MAIN_CARD.CATEGORY_CD.`as`(ArticleMainCardRecord::categoryCd.name),
ARTICLE_MAIN_CARD.CREATED_AT.`as`(ArticleMainCardRecord::createdAt.name),
ARTICLE_MAIN_CARD.WRITER_ID.`as`(ArticleMainCardRecord::writerId.name),
ARTICLE_MAIN_CARD.WRITER_EMAIL.`as`(ArticleMainCardRecord::writerEmail.name),
jsonGetAttributeAsText(
ARTICLE_MAIN_CARD.WRITER_DESCRIPTION,
"name",
).`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),
).from(ARTICLE_MAIN_CARD)
.where(ARTICLE_MAIN_CARD.ID.eq(it))
.fetch(articleMainCardMapper)
.firstOrNull()
}.toSet()
}
}

fun selectArticleMainCardsRecordQuery(articleIds: Set<Long>) =
dslContext
Expand Down

0 comments on commit c54ee6b

Please sign in to comment.