thread-master/apps/backend/internal/module/scout/domain/pagination.go

54 lines
906 B
Go
Raw Normal View History

2026-08-13 02:22:24 +00:00
package domain
const (
DefaultPageSize = 10
MaxPageSize = 50
)
type PageInfo struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Total int64 `json:"total"`
TotalPages int `json:"totalPages"`
}
func NormalizePage(page, pageSize int) PageInfo {
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = DefaultPageSize
}
if pageSize > MaxPageSize {
pageSize = MaxPageSize
}
return PageInfo{Page: page, PageSize: pageSize}
}
func (p PageInfo) WithTotal(total int64) PageInfo {
p.Total = total
if total > 0 {
p.TotalPages = int((total + int64(p.PageSize) - 1) / int64(p.PageSize))
}
return p
}
type RunFilter struct {
OwnerUID int64
BrandID string
Mode string
Page int
PageSize int
}
type RunPage struct {
Items []*Run
Pagination PageInfo
}
type RunPostPage struct {
Run *Run
Items []*Post
Pagination PageInfo
}