feat(kol): workspace KOL cards + article source type
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- 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
|
||||
|
||||
@@ -46,3 +46,19 @@ FROM tenant_plan_subscriptions s
|
||||
JOIN plans p ON p.id = s.plan_id
|
||||
WHERE s.tenant_id = sqlc.arg(tenant_id) AND s.status = 'active' AND s.deleted_at IS NULL
|
||||
LIMIT 1;
|
||||
|
||||
-- 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 = sqlc.arg(tenant_id)::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;
|
||||
|
||||
@@ -28,6 +28,16 @@ type WorkspacePlan struct {
|
||||
EndAt time.Time
|
||||
}
|
||||
|
||||
type WorkspaceKolCard struct {
|
||||
SubscriptionPromptID int64
|
||||
GrantedAt time.Time
|
||||
PromptName string
|
||||
PlatformHint *string
|
||||
PackageName string
|
||||
PackageCover *string
|
||||
KolDisplayName string
|
||||
}
|
||||
|
||||
type WorkspaceRepository interface {
|
||||
CountArticlesByTenant(ctx context.Context, tenantID int64) (int64, error)
|
||||
CountPublishedArticlesByTenant(ctx context.Context, tenantID int64) (int64, error)
|
||||
@@ -35,6 +45,7 @@ type WorkspaceRepository interface {
|
||||
GetRecentArticles(ctx context.Context, tenantID int64) ([]WorkspaceRecentArticle, error)
|
||||
GetQuotaSummary(ctx context.Context, tenantID int64) (int, error)
|
||||
GetActivePlanForTenant(ctx context.Context, tenantID int64) (*WorkspacePlan, error)
|
||||
ListKolCards(ctx context.Context, tenantID int64) ([]WorkspaceKolCard, error)
|
||||
}
|
||||
|
||||
type workspaceRepository struct {
|
||||
@@ -104,3 +115,25 @@ func (r *workspaceRepository) GetActivePlanForTenant(ctx context.Context, tenant
|
||||
EndAt: timeFromTimestamp(row.EndAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *workspaceRepository) ListKolCards(ctx context.Context, tenantID int64) ([]WorkspaceKolCard, error) {
|
||||
rows, err := r.q.ListKolCardsForTenant(ctx, tenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cards := make([]WorkspaceKolCard, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
cards = append(cards, WorkspaceKolCard{
|
||||
SubscriptionPromptID: row.SubscriptionPromptID,
|
||||
GrantedAt: timeFromTimestamp(row.GrantedAt),
|
||||
PromptName: row.PromptName,
|
||||
PlatformHint: nullableText(row.PlatformHint),
|
||||
PackageName: row.PackageName,
|
||||
PackageCover: nullableText(row.PackageCover),
|
||||
KolDisplayName: row.KolDisplayName,
|
||||
})
|
||||
}
|
||||
|
||||
return cards, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user