Skip to content

Commit 04f3a3b

Browse files
committed
Refactor pagination logic by extracting calculatePage method
1 parent 8ad6093 commit 04f3a3b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core-impl/src/main/kotlin/io/github/gunkim/realworld/infrastructure/jdbc/article/repository/ArticleReadRepositoryImpl.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class ArticleReadRepositoryImpl(
2424
limit: Int,
2525
offset: Int,
2626
): List<Article> {
27-
val page = offset / limit
27+
val page = calculatePage(offset, limit)
2828
val pageable = PageRequest.of(page, limit)
2929

3030
val spec = buildArticleSpecification(tag, author, favoritedUsername)
3131
return articleDao.findAll(spec, pageable).content
3232
}
3333

3434
override fun findFeedArticles(userId: UserId, limit: Int, offset: Int): List<Article> {
35-
val page = offset / limit
35+
val page = calculatePage(offset, limit)
3636
val pageable = PageRequest.of(page, limit)
3737

3838
return articleDao.findFeedArticles(userId, pageable)
@@ -48,4 +48,6 @@ class ArticleReadRepositoryImpl(
4848

4949
override fun findBySlug(slug: Slug): Article? =
5050
articleDao.findBySlug(slug)
51-
}
51+
52+
private fun calculatePage(offset: Int, limit: Int) = offset / limit
53+
}

0 commit comments

Comments
 (0)