feat: add PageInfo model for pagination
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5bf77ede5c
commit
113789a972
28
models/paging.go
Normal file
28
models/paging.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
// PageInfo carries pagination state for templates.
|
||||||
|
type PageInfo struct {
|
||||||
|
CurrentPage int
|
||||||
|
TotalPages int
|
||||||
|
PostsPerPage int
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPrevious returns true if there is a previous page.
|
||||||
|
func (p PageInfo) HasPrevious() bool {
|
||||||
|
return p.CurrentPage > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasNext returns true if there is a next page.
|
||||||
|
func (p PageInfo) HasNext() bool {
|
||||||
|
return p.CurrentPage < p.TotalPages
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreviousPage returns the previous page number.
|
||||||
|
func (p PageInfo) PreviousPage() int {
|
||||||
|
return p.CurrentPage - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NextPage returns the next page number.
|
||||||
|
func (p PageInfo) NextPage() int {
|
||||||
|
return p.CurrentPage + 1
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue