fix: technical debts left by the Sites, Authors and SEO slices, plus backend support for the new Sites and Authors pagination

This commit is contained in:
Florian Sylvain committed 2026-10-19 00:25:31 +02:00
1 parent 9f4ce426a8
commit daf3594316
86 files changed
+4223 -1485

No files matched your search

@@ -42,6 +42,11 @@ func (u *ListArticlesUseCase) ListArticlesPage(command ListArticlesCommand) (Art
if err != nil {
return ArticlePage{}, err
}
summaries, err := u.summarizeVisible(!command.Verified)
if err != nil {
return ArticlePage{}, err
}
counts.Suggestions = countSuggestions(summaries)
page := ArticlePage{Items: []article.Article{}, Page: command.Page, Size: command.Size, Counts: counts, SEO: map[uint32]article.SEOSummary{}}
if !command.Verified && command.Status == article.StatusDraft {
return page, nil
@@ -62,10 +67,6 @@ func (u *ListArticlesUseCase) ListArticlesPage(command ListArticlesCommand) (Art
if err != nil {
return ArticlePage{}, err
}
summaries, err := u.summarize(found.Items)
if err != nil {
return ArticlePage{}, err
}
items, total := found.Items, found.Total
if command.SEO != "" {
items, total = pageBySEOStatus(found.Items, summaries, command)
@@ -80,6 +81,29 @@ func (u *ListArticlesUseCase) ListArticlesPage(command ListArticlesCommand) (Art
return page, nil
}
func (u *ListArticlesUseCase) summarizeVisible(onlineOnly bool) (map[uint32]article.SEOSummary, error) {
filters := article.Filters{Unpaged: true}
if onlineOnly {
online := true
filters.IsOnline = &online
}
found, err := u.articleRepository.FindPage(filters)
if err != nil {
return nil, err
}
return u.summarize(found.Items)
}
func countSuggestions(summaries map[uint32]article.SEOSummary) int {
suggestions := 0
for _, summary := range summaries {
if summary.Status == article.SEOStatusSuggestions {
suggestions++
}
}
return suggestions
}
func pageBySEOStatus(items []article.Article, summaries map[uint32]article.SEOSummary, command ListArticlesCommand) ([]article.Article, int) {
matching := make([]article.Article, 0, len(items))
for _, item := range items {
@@ -82,8 +82,7 @@ func (l *ListMediaUseCase) List(query image.ListQuery) (MediaPage, error) {
}
}
offset := (query.Page - 1) * query.Size
pageStart := min(offset, len(matching))
pageStart := min(min(query.Page-1, len(matching))*query.Size, len(matching))
pageEnd := min(pageStart+query.Size, len(matching))
names := newUploaderNames(l.userRepository)
items := []MediaItem{}
@@ -106,6 +105,14 @@ func (l *ListMediaUseCase) List(query image.ListQuery) (MediaPage, error) {
return MediaPage{Items: items, Total: len(matching), Page: query.Page, Size: query.Size, Counts: counts}, nil
}
func (l *ListMediaUseCase) Get(id uint32) (MediaItem, error) {
found, err := l.imageRepository.Get(id)
if err != nil {
return MediaItem{}, err
}
return l.Describe(found)
}
func (l *ListMediaUseCase) Describe(img image.Image) (MediaItem, error) {
articleCount, err := l.articleUsageCount(img)
if err != nil {
@@ -6,6 +6,17 @@ type ListSitesUseCase struct {
siteRepository site.Repository
}
type ListSitesCommand struct {
Q string
Page int
Size int
}
type SitePage struct {
Items []site.Site
Total int
}
func NewListSitesUseCase(siteRepository site.Repository) *ListSitesUseCase {
return &ListSitesUseCase{siteRepository}
}
@@ -13,3 +24,11 @@ func NewListSitesUseCase(siteRepository site.Repository) *ListSitesUseCase {
func (u *ListSitesUseCase) List() ([]site.Site, error) {
return u.siteRepository.List()
}
func (u *ListSitesUseCase) ListPage(command ListSitesCommand) (SitePage, error) {
found, err := u.siteRepository.Find(site.ListQuery{Q: command.Q, Page: command.Page, Size: command.Size})
if err != nil {
return SitePage{}, err
}
return SitePage{Items: found.Items, Total: found.Total}, nil
}