You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
684 B
28 lines
684 B
package common
|
|
|
|
import "math"
|
|
|
|
type PageRequest[T any] struct {
|
|
Page Pagination `json:"page"`
|
|
OrderBy string `json:"order_by"`
|
|
Desc bool `json:"desc"`
|
|
Query T `json:"query"`
|
|
}
|
|
|
|
type PageResponse[T any] struct {
|
|
PageNum int64 `json:"pageNum"`
|
|
PageSize int64 `json:"pageSize"`
|
|
Pages int `json:"pages"`
|
|
Total int `json:"total"`
|
|
Records []T `json:"records"`
|
|
}
|
|
|
|
func Page[T any](page Pagination, total int64, records []T) *PageResponse[T] {
|
|
return &PageResponse[T]{
|
|
PageNum: page.PageNum,
|
|
PageSize: page.PageSize,
|
|
Pages: int(math.Ceil(float64(total) / float64(page.PageSize))),
|
|
Total: int(total),
|
|
Records: records,
|
|
}
|
|
}
|
|
|