feat: scope articles by brand

This commit is contained in:
2026-05-20 15:37:25 +08:00
parent 5fb9d0b0dd
commit dd082e2ed1
72 changed files with 3213 additions and 432 deletions
@@ -46,12 +46,16 @@ func (s *WorkspaceService) WithCache(c sharedcache.Cache) *WorkspaceService {
func (s *WorkspaceService) Overview(ctx context.Context) (*domain.WorkspaceOverview, error) {
actor := auth.MustActor(ctx)
return sharedcache.LoadJSON(ctx, s.cache, &s.cacheGroup, workspaceOverviewCacheKey(actor.TenantID), defaultCacheTTL(), func(loadCtx context.Context) (*domain.WorkspaceOverview, error) {
articleCount, err := s.repo.CountArticlesByTenant(loadCtx, actor.TenantID)
brandID, err := requireCurrentBrandID(ctx)
if err != nil {
return nil, err
}
return sharedcache.LoadJSON(ctx, s.cache, &s.cacheGroup, workspaceOverviewCacheKey(actor.TenantID, brandID), defaultCacheTTL(), func(loadCtx context.Context) (*domain.WorkspaceOverview, error) {
articleCount, err := s.repo.CountArticlesByTenantAndBrand(loadCtx, actor.TenantID, brandID)
if err != nil {
return nil, response.ErrInternal(50010, "query_failed", "failed to count articles")
}
publishedCount, err := s.repo.CountPublishedArticlesByTenant(loadCtx, actor.TenantID)
publishedCount, err := s.repo.CountPublishedArticlesByTenantAndBrand(loadCtx, actor.TenantID, brandID)
if err != nil {
return nil, response.ErrInternal(50010, "query_failed", "failed to count published articles")
}
@@ -69,8 +73,12 @@ func (s *WorkspaceService) Overview(ctx context.Context) (*domain.WorkspaceOverv
func (s *WorkspaceService) RecentArticles(ctx context.Context) ([]domain.RecentArticle, error) {
actor := auth.MustActor(ctx)
return sharedcache.LoadJSON(ctx, s.cache, &s.cacheGroup, workspaceRecentArticlesCacheKey(actor.TenantID), defaultCacheTTL(), func(loadCtx context.Context) ([]domain.RecentArticle, error) {
rows, err := s.repo.GetRecentArticles(loadCtx, actor.TenantID)
brandID, err := requireCurrentBrandID(ctx)
if err != nil {
return nil, err
}
return sharedcache.LoadJSON(ctx, s.cache, &s.cacheGroup, workspaceRecentArticlesCacheKey(actor.TenantID, brandID), defaultCacheTTL(), func(loadCtx context.Context) ([]domain.RecentArticle, error) {
rows, err := s.repo.GetRecentArticlesByBrand(loadCtx, actor.TenantID, brandID)
if err != nil {
return nil, response.ErrInternal(50010, "query_failed", "failed to fetch recent articles")
}
@@ -79,6 +87,7 @@ func (s *WorkspaceService) RecentArticles(ctx context.Context) ([]domain.RecentA
for _, row := range rows {
articles = append(articles, domain.RecentArticle{
ID: row.ID,
BrandID: row.BrandID,
GenerateStatus: row.GenerateStatus,
PublishStatus: row.PublishStatus,
SourceType: row.SourceType,