feat: articles pagination
This commit is contained in:
1 parent
a2d224240c
commit
73f4b539fe
45 files changed
+3528
-317
No files matched your search
@@ -1,11 +1,57 @@
|
||||
package article
|
||||
|
||||
const (
|
||||
StatusOnline = "online"
|
||||
StatusDraft = "draft"
|
||||
)
|
||||
|
||||
type SortField string
|
||||
|
||||
type SortDirection string
|
||||
|
||||
const (
|
||||
SortByTitle SortField = "title"
|
||||
SortByStatus SortField = "status"
|
||||
SortByCreatedAt SortField = "created_at"
|
||||
SortByUpdatedAt SortField = "updated_at"
|
||||
|
||||
SortAsc SortDirection = "asc"
|
||||
SortDesc SortDirection = "desc"
|
||||
)
|
||||
|
||||
type Sort struct {
|
||||
Field SortField
|
||||
Direction SortDirection
|
||||
}
|
||||
|
||||
func DefaultSort() Sort {
|
||||
return Sort{Field: SortByUpdatedAt, Direction: SortDesc}
|
||||
}
|
||||
|
||||
type Filters struct {
|
||||
IsOnline *bool
|
||||
Page int
|
||||
Size int
|
||||
Q string
|
||||
Status string
|
||||
Sort Sort
|
||||
}
|
||||
|
||||
type Counts struct {
|
||||
All int `json:"all"`
|
||||
Online int `json:"online"`
|
||||
Draft int `json:"draft"`
|
||||
}
|
||||
|
||||
type PageResult struct {
|
||||
Items []Article
|
||||
Total int
|
||||
}
|
||||
|
||||
type Repository interface {
|
||||
FindByFilters(filters Filters) ([]Article, error)
|
||||
FindPage(filters Filters) (PageResult, error)
|
||||
CountByVisibility(onlineOnly bool) (Counts, error)
|
||||
Get(id uint32) (Article, error)
|
||||
GetByName(name string) (Article, error)
|
||||
GetAll() []Article
|
||||
|
||||
Reference in new issue
Block a user