feat(kol): workspace KOL cards + article source type

This commit is contained in:
2026-04-17 15:19:11 +08:00
parent 641383a585
commit b6bd4f02fb
16 changed files with 192 additions and 5 deletions
@@ -208,7 +208,7 @@ func (q *Queries) GetArticleVersions(ctx context.Context, articleID int64) ([]Ge
}
const listArticles = `-- name: ListArticles :many
SELECT a.id, a.tenant_id, a.source_type, a.template_id,
SELECT a.id, a.tenant_id, a.source_type, a.template_id, a.kol_prompt_id,
a.generate_status, a.publish_status, a.created_at, a.updated_at,
av.title, av.word_count, av.source_label,
t.template_name
@@ -242,6 +242,7 @@ type ListArticlesRow struct {
TenantID int64 `json:"tenant_id"`
SourceType string `json:"source_type"`
TemplateID pgtype.Int8 `json:"template_id"`
KolPromptID pgtype.Int8 `json:"kol_prompt_id"`
GenerateStatus string `json:"generate_status"`
PublishStatus string `json:"publish_status"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
@@ -275,6 +276,7 @@ func (q *Queries) ListArticles(ctx context.Context, arg ListArticlesParams) ([]L
&i.TenantID,
&i.SourceType,
&i.TemplateID,
&i.KolPromptID,
&i.GenerateStatus,
&i.PublishStatus,
&i.CreatedAt,
@@ -100,6 +100,7 @@ type Querier interface {
ListImageReferenceArticles(ctx context.Context, arg ListImageReferenceArticlesParams) ([]ListImageReferenceArticlesRow, error)
ListImageReferences(ctx context.Context, arg ListImageReferencesParams) ([]ListImageReferencesRow, error)
ListKeywords(ctx context.Context, arg ListKeywordsParams) ([]ListKeywordsRow, error)
ListKolCardsForTenant(ctx context.Context, tenantID int64) ([]ListKolCardsForTenantRow, error)
ListKolPackageIDsByProfile(ctx context.Context, arg ListKolPackageIDsByProfileParams) ([]int64, error)
ListKolPackagesByProfile(ctx context.Context, arg ListKolPackagesByProfileParams) ([]ListKolPackagesByProfileRow, error)
ListKolPromptsByPackage(ctx context.Context, arg ListKolPromptsByPackageParams) ([]ListKolPromptsByPackageRow, error)
@@ -160,3 +160,58 @@ func (q *Queries) GetRecentArticles(ctx context.Context, tenantID int64) ([]GetR
}
return items, nil
}
const listKolCardsForTenant = `-- name: ListKolCardsForTenant :many
SELECT sp.id AS subscription_prompt_id, sp.granted_at,
p.name AS prompt_name, p.platform_hint,
k.name AS package_name, k.cover_url AS package_cover,
pf.display_name AS kol_display_name
FROM kol_subscription_prompts sp
JOIN kol_prompts p ON p.id = sp.prompt_id AND p.deleted_at IS NULL
JOIN kol_packages k ON k.id = sp.package_id AND k.deleted_at IS NULL
JOIN kol_profiles pf ON pf.id = k.kol_profile_id
WHERE sp.tenant_id = $1::bigint
AND sp.status = 'active'
AND p.status = 'active'
AND p.published_revision_no IS NOT NULL
ORDER BY sp.granted_at DESC
LIMIT 8
`
type ListKolCardsForTenantRow struct {
SubscriptionPromptID int64 `json:"subscription_prompt_id"`
GrantedAt pgtype.Timestamptz `json:"granted_at"`
PromptName string `json:"prompt_name"`
PlatformHint pgtype.Text `json:"platform_hint"`
PackageName string `json:"package_name"`
PackageCover pgtype.Text `json:"package_cover"`
KolDisplayName string `json:"kol_display_name"`
}
func (q *Queries) ListKolCardsForTenant(ctx context.Context, tenantID int64) ([]ListKolCardsForTenantRow, error) {
rows, err := q.db.Query(ctx, listKolCardsForTenant, tenantID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListKolCardsForTenantRow
for rows.Next() {
var i ListKolCardsForTenantRow
if err := rows.Scan(
&i.SubscriptionPromptID,
&i.GrantedAt,
&i.PromptName,
&i.PlatformHint,
&i.PackageName,
&i.PackageCover,
&i.KolDisplayName,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}