Files
RenewCMS/internal/domain/article/articleRepositoryInterface.go
T

64 lines
1.3 KiB
Go

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
Create(post Article) (Article, error)
UpdateBody(id uint32, body string) (Article, error)
UpdateIsOnline(id uint32, isOnline bool) (Article, error)
Delete(id uint32) error
FindByBodyContaining(filename string) ([]Article, error)
}