feat: scope articles by brand
This commit is contained in:
@@ -88,10 +88,14 @@ func (s *MediaService) ListPlatforms(ctx context.Context) ([]MediaPlatformRespon
|
||||
|
||||
func (s *MediaService) ListArticlePublishRecords(ctx context.Context, articleID int64) ([]PublishRecordResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
return s.listArticlePublishRecords(ctx, actor.TenantID, articleID)
|
||||
brandID, err := requireCurrentBrandID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.listArticlePublishRecords(ctx, actor.TenantID, brandID, articleID)
|
||||
}
|
||||
|
||||
func (s *MediaService) listArticlePublishRecords(ctx context.Context, tenantID, articleID int64) ([]PublishRecordResponse, error) {
|
||||
func (s *MediaService) listArticlePublishRecords(ctx context.Context, tenantID, brandID, articleID int64) ([]PublishRecordResponse, error) {
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT pr.id, pr.publish_batch_id, pr.article_id, pr.platform_account_id, pr.platform_id,
|
||||
mp.name, pa.nickname, pr.status, pr.external_article_id, pr.external_article_url,
|
||||
@@ -99,9 +103,10 @@ func (s *MediaService) listArticlePublishRecords(ctx context.Context, tenantID,
|
||||
FROM publish_records pr
|
||||
JOIN media_platforms mp ON mp.platform_id = pr.platform_id
|
||||
JOIN platform_accounts pa ON pa.id = pr.platform_account_id
|
||||
WHERE pr.tenant_id = $1 AND pr.article_id = $2
|
||||
JOIN articles a ON a.id = pr.article_id AND a.tenant_id = pr.tenant_id
|
||||
WHERE pr.tenant_id = $1 AND pr.article_id = $2 AND a.brand_id = $3 AND a.deleted_at IS NULL
|
||||
ORDER BY pr.created_at DESC, pr.id DESC
|
||||
`, tenantID, articleID)
|
||||
`, tenantID, articleID, brandID)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50043, "publish_record_query_failed", "failed to list publish records")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user