-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.go
More file actions
69 lines (61 loc) 路 2.45 KB
/
Copy pathmodels.go
File metadata and controls
69 lines (61 loc) 路 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package pagorminator
import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"github.com/manuelarte/pagorminator/cursorpagination"
"github.com/manuelarte/pagorminator/pagegeneric"
"github.com/manuelarte/pagorminator/pagepagination"
)
var (
_ Pagination = new(cursorpagination.Pagination)
_ Nexter[*cursorpagination.Pagination] = new(cursorpagination.Pagination)
_ Pagination = new(pagepagination.Pagination)
_ Nexter[*pagepagination.Pagination] = new(pagepagination.Pagination)
_ Prever[*pagepagination.Pagination] = new(pagepagination.Pagination)
)
type (
// PaginationRequest is the interface that contains the information about the pagination.
PaginationRequest interface {
// Size returns the pagination size, a.k.a. limit
Size() int
// IsUnPaged returns true if the pagination is unpaged, meaning no pagination is applied.
IsUnPaged() bool
}
// Nexter is the interface that indicates that you can ask for the next page.
Nexter[P PaginationRequest] interface {
// Next returns the next page and whether the next page could be retrieved.
// If the next page could not be retrieved, the second return value is false.
// Examples of cases can't be retrieved:
// - No next page
// - The total elements are not set
Next() (P, pagegeneric.PrevNextPossible)
}
// Prever is the interface that indicates that you can ask for the previous page.
Prever[P PaginationRequest] interface {
// Prev returns the previous page and whether the previous page could be retrieved.
// If the previous page could not be retrieved, the second return value is false.
// Examples of cases can't be retrieved:
// - No previous page
// - The total elements are not set
Prev() (P, pagegeneric.PrevNextPossible)
}
// PaginationCountResponse is the interface that contains the information after a count query.
PaginationCountResponse interface {
// GetTotalElements returns the total elements.
// It also returns if the total element was set.
TotalElements() (int64, bool)
// SetTotalElements sets the total elements.
//
// Errors:
// - ErrTotalElementsNotValid if the total elements are below zero.
SetTotalElements(totalElements int64) error
IsTotalElementsSet() bool
}
// Pagination is the interface that combines the pagination request and the pagination count response.
Pagination interface {
PaginationRequest
PaginationCountResponse
clause.Expression
gorm.StatementModifier
}
)