handling if whereQuery is not needed

main v1.0.12
alex 2023-10-13 15:41:38 +02:00
parent 6a6d2c7042
commit 56821c2833
1 changed files with 8 additions and 3 deletions

View File

@ -11,9 +11,14 @@ import (
func GetTotalPages(database *gorm.DB, paginationLimit int, any interface{}, whereQuery interface{}, args ...interface{}) int {
var totalPages int64
database.Model(any).
Where(whereQuery, args).
Count(&totalPages)
if whereQuery == nil {
database.Model(any).
Count(&totalPages)
} else {
database.Model(any).
Where(whereQuery, args).
Count(&totalPages)
}
return int(math.Ceil(float64(totalPages) / float64(paginationLimit)))
}