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))
}

View File

@@ -7,13 +7,5 @@ const (
// GetPageOffset 计算偏移量
func GetPageOffset(pageNum, pageSize int32) int {
if pageNum < 1 {
pageNum = DefaultPage
}
if pageSize < 1 {
pageSize = DefaultPageSize
}
return int((pageNum - 1) * pageSize)
}

View File

@@ -1,6 +1,6 @@
git tag v1.1.2
git tag v1.1.3
git tag bank_card/v1.1.0
git tag entgo/v1.1.2
git tag entgo/v1.1.3
git tag geoip/v1.1.0
git push origin --tags