105 lines
2.3 KiB
Go
105 lines
2.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"
|
|
SortByID SortField = "id"
|
|
|
|
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
|
|
SiteID *uint32
|
|
Page int
|
|
Size int
|
|
Q string
|
|
Status string
|
|
Sort Sort
|
|
Unpaged bool
|
|
}
|
|
|
|
type Nullable[T any] struct {
|
|
Set bool
|
|
Value *T
|
|
}
|
|
|
|
type Update struct {
|
|
Body *string
|
|
SiteID *uint32
|
|
AuthorIDs *[]uint32
|
|
Slug *string
|
|
Excerpt *string
|
|
SEOTitle *string
|
|
SEODescription *string
|
|
CoverImageID Nullable[uint32]
|
|
CoverImageAlt *string
|
|
SocialTitle *string
|
|
SocialDescription *string
|
|
SocialImageID Nullable[uint32]
|
|
CanonicalURL *string
|
|
Noindex *bool
|
|
SEODismissed *[]string
|
|
}
|
|
|
|
type ImageReferences struct {
|
|
Cover []uint32
|
|
Social []uint32
|
|
}
|
|
|
|
func (r ImageReferences) Empty() bool {
|
|
return len(r.Cover) == 0 && len(r.Social) == 0
|
|
}
|
|
|
|
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)
|
|
Update(id uint32, update Update) (Article, error)
|
|
UpdateIsOnline(id uint32, isOnline bool) (Article, error)
|
|
Delete(id uint32) error
|
|
FindByBodyContaining(filename string) ([]Article, error)
|
|
FindByImage(imageID uint32) ([]Article, error)
|
|
SlugTaken(siteID uint32, slug string, exceptID uint32) (bool, error)
|
|
ClearImage(imageID uint32) (ImageReferences, error)
|
|
RestoreImage(references ImageReferences, imageID uint32) error
|
|
RepointImage(fromImageIDs []uint32, toImageID uint32) ([]uint32, error)
|
|
}
|