reprogl
1package models
2
3type (
4PaginationDirection uint
5URLGenerator func(int, PaginationDirection) string
6)
7
8const (
9PaginationNext PaginationDirection = iota
10PaginationPrev
11)
12
13type ArticlesPaginator struct {
14Items ArticleList
15CurrentPage int
16PageCount int
17URLGenerator URLGenerator
18}
19
20func (p *ArticlesPaginator) HasPrevious() bool {
21return p.CurrentPage > 1
22}
23
24func (p *ArticlesPaginator) HasNext() bool {
25return p.CurrentPage < p.PageCount
26}
27
28func (p *ArticlesPaginator) PreviousPageURL() string {
29return p.URLGenerator(p.CurrentPage, PaginationPrev)
30}
31
32func (p *ArticlesPaginator) NextPageURL() string {
33return p.URLGenerator(p.CurrentPage, PaginationNext)
34}
35