fix: pagination bug.

This commit is contained in:
tx7do
2023-10-28 20:14:31 +08:00
parent 82fbdc15d9
commit 9990fa43e0
4 changed files with 10 additions and 11 deletions

View File

@@ -8,7 +8,7 @@ require (
github.com/go-kratos/kratos/v2 v2.7.1
github.com/google/uuid v1.4.0
github.com/stretchr/testify v1.8.4
github.com/tx7do/go-utils v1.1.0
github.com/tx7do/go-utils v1.1.3
)
require (

View File

@@ -17,6 +17,13 @@ func BuildPaginationSelector(page, pageSize int32, noPaging bool) func(*sql.Sele
}
func BuildPaginationSelect(s *sql.Selector, page, pageSize int32) {
if page < 1 {
page = paging.DefaultPage
}
if pageSize < 1 {
pageSize = paging.DefaultPageSize
}
offset := paging.GetPageOffset(page, pageSize)
s.Offset(offset).Limit(int(pageSize))
}