64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package useCases
|
|
|
|
import (
|
|
"RenewCMS/internal/domain/article"
|
|
"RenewCMS/internal/domain/author"
|
|
"RenewCMS/internal/domain/image"
|
|
"RenewCMS/internal/domain/site"
|
|
)
|
|
|
|
const purgePreviewListLimit = 5
|
|
|
|
type PurgePreviewGroup struct {
|
|
KeepID uint32
|
|
Filename string
|
|
URL string
|
|
UsedIn int
|
|
Merged int
|
|
}
|
|
|
|
type PurgePreview struct {
|
|
Groups int
|
|
Copies int
|
|
Articles int
|
|
List []PurgePreviewGroup
|
|
More int
|
|
Fingerprint string
|
|
}
|
|
|
|
type PreviewPurgeUseCase struct {
|
|
planner *purgePlanner
|
|
}
|
|
|
|
func NewPreviewPurgeUseCase(imageRepository image.Repository, articleRepository article.Repository, sites site.Repository, authors author.Repository) *PreviewPurgeUseCase {
|
|
return &PreviewPurgeUseCase{&purgePlanner{imageRepository: imageRepository, articleRepository: articleRepository, sites: sites, authors: authors}}
|
|
}
|
|
|
|
func (u *PreviewPurgeUseCase) Preview() (PurgePreview, error) {
|
|
plan, err := u.planner.plan()
|
|
if err != nil {
|
|
return PurgePreview{}, err
|
|
}
|
|
|
|
shown := min(len(plan.groups), purgePreviewListLimit)
|
|
list := make([]PurgePreviewGroup, 0, shown)
|
|
for _, group := range plan.groups[:shown] {
|
|
list = append(list, PurgePreviewGroup{
|
|
KeepID: group.kept.ID,
|
|
Filename: group.kept.Filename,
|
|
URL: group.kept.Path,
|
|
UsedIn: group.keptUsage,
|
|
Merged: len(group.mergedIds),
|
|
})
|
|
}
|
|
|
|
return PurgePreview{
|
|
Groups: len(plan.groups),
|
|
Copies: plan.copies,
|
|
Articles: plan.articles,
|
|
List: list,
|
|
More: len(plan.groups) - shown,
|
|
Fingerprint: plan.fingerprint,
|
|
}, nil
|
|
}
|