From f15bcaa09974ac2e0b84541f70085a8c599afd9c Mon Sep 17 00:00:00 2001 From: Shiina Kin Date: Sun, 20 Oct 2024 20:57:44 +0800 Subject: [PATCH] refactor: add totalPage field to PageResult --- app/src/main/kotlin/io/sakurasou/controller/vo/CommonVO.kt | 1 + .../main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt | 2 ++ app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt | 1 + .../kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt | 1 + 4 files changed, 5 insertions(+) diff --git a/app/src/main/kotlin/io/sakurasou/controller/vo/CommonVO.kt b/app/src/main/kotlin/io/sakurasou/controller/vo/CommonVO.kt index bbc2819b..10879519 100644 --- a/app/src/main/kotlin/io/sakurasou/controller/vo/CommonVO.kt +++ b/app/src/main/kotlin/io/sakurasou/controller/vo/CommonVO.kt @@ -11,6 +11,7 @@ data class PageResult( val page: Long, val pageSize: Int, val total: Long, + val totalPage: Long, val data: List ) diff --git a/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt b/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt index 14e37a50..dd043220 100644 --- a/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt +++ b/app/src/main/kotlin/io/sakurasou/model/dao/common/PaginationDao.kt @@ -26,6 +26,7 @@ interface PaginationDao { val offset = (page - 1) * pageSize val totalRecords: Long = customWhereCond(table.selectAll()).count() + val totalPage: Long = (totalRecords + pageSize - 1) / pageSize val query = table.selectAll().limit(pageSize).offset(offset) pageRequest.orderBy?.let { @@ -42,6 +43,7 @@ interface PaginationDao { page = page, pageSize = pageSize, total = totalRecords, + totalPage = totalPage, data = data ) return pageResult diff --git a/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt b/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt index 254da2a2..cadf0c3b 100644 --- a/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/model/dao/user/UserDaoImpl.kt @@ -123,6 +123,7 @@ class UserDaoImpl : UserDao { page = page, pageSize = pageSize, total = totalRecords, + totalPage = (totalRecords + pageSize - 1) / pageSize, data = data ) return pageResult diff --git a/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt index f0b2ab9c..493fe2aa 100644 --- a/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/strategy/StrategyServiceImpl.kt @@ -92,6 +92,7 @@ class StrategyServiceImpl( page = strategyPageResult.page, pageSize = strategyPageResult.pageSize, total = strategyPageResult.total, + totalPage = strategyPageResult.totalPage, data = pageVOList ) }