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
@@ -2,12 +2,14 @@ package app
import (
"context"
"errors"
"github.com/geo-platform/tenant-api/internal/shared/auditlog"
sharedcache "github.com/geo-platform/tenant-api/internal/shared/cache"
"github.com/geo-platform/tenant-api/internal/shared/objectstorage"
"github.com/geo-platform/tenant-api/internal/shared/response"
"github.com/geo-platform/tenant-api/internal/tenant/repository"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
@@ -43,7 +45,11 @@ func (s *DesktopContentService) Article(
return nil, response.ErrUnauthorized(40108, "desktop_client_missing", "desktop client context is required")
}
detail, found, err := s.articles.loadArticleDetail(ctx, client.TenantID, articleID)
brandID, err := s.articleBrandID(ctx, client.TenantID, articleID)
if err != nil {
return nil, err
}
detail, found, err := s.articles.loadArticleDetail(ctx, client.TenantID, brandID, articleID)
if err != nil {
return nil, err
}
@@ -64,3 +70,23 @@ func (s *DesktopContentService) Article(
CoverAssetURL: detail.CoverAssetURL,
}, nil
}
func (s *DesktopContentService) articleBrandID(ctx context.Context, tenantID, articleID int64) (int64, error) {
if s == nil || s.articles == nil || s.articles.pool == nil {
return 0, response.ErrInternal(50012, "article_lookup_unavailable", "article lookup is unavailable")
}
var brandID int64
if err := s.articles.pool.QueryRow(ctx, `
SELECT brand_id
FROM articles
WHERE id = $1
AND tenant_id = $2
AND deleted_at IS NULL
`, articleID, tenantID).Scan(&brandID); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return 0, response.ErrNotFound(40411, "article_not_found", "article not found")
}
return 0, response.ErrInternal(50010, "query_failed", "failed to load article")
}
return brandID, nil
}