feat(kol): marketplace + subscription admin services + publish fan-out

This commit is contained in:
2026-04-17 14:23:32 +08:00
parent df334c1e26
commit 99fc6c1af4
4 changed files with 565 additions and 2 deletions
@@ -69,6 +69,7 @@ type KolPromptService struct {
profileSvc *KolProfileService
pkgRepo repository.KolPackageRepository
promptRepo repository.KolPromptRepository
subRepo repository.KolSubscriptionRepository
asset *KolPromptAsset
}
@@ -77,6 +78,7 @@ func NewKolPromptService(
profileSvc *KolProfileService,
pkgRepo repository.KolPackageRepository,
promptRepo repository.KolPromptRepository,
subRepo repository.KolSubscriptionRepository,
asset *KolPromptAsset,
) *KolPromptService {
return &KolPromptService{
@@ -84,6 +86,7 @@ func NewKolPromptService(
profileSvc: profileSvc,
pkgRepo: pkgRepo,
promptRepo: promptRepo,
subRepo: subRepo,
asset: asset,
}
}
@@ -251,7 +254,7 @@ func (s *KolPromptService) SaveDraft(ctx context.Context, actor auth.Actor, inpu
}
func (s *KolPromptService) Publish(ctx context.Context, actor auth.Actor, promptID int64) error {
_, prompt, _, err := s.loadOwnedPrompt(ctx, actor, promptID)
_, prompt, pkg, err := s.loadOwnedPrompt(ctx, actor, promptID)
if err != nil {
return err
}
@@ -265,10 +268,28 @@ func (s *KolPromptService) Publish(ctx context.Context, actor auth.Actor, prompt
}
defer tx.Rollback(ctx)
if err := repository.NewKolPromptRepository(tx).SetPublishedRevision(ctx, actor.TenantID, promptID, *prompt.DraftRevisionNo, actor.UserID); err != nil {
promptTx := repository.NewKolPromptRepository(tx)
subTx := repository.NewKolSubscriptionRepository(tx)
if err := promptTx.SetPublishedRevision(ctx, actor.TenantID, promptID, *prompt.DraftRevisionNo, actor.UserID); err != nil {
return response.ErrInternal(50080, "kol_prompt_publish_failed", err.Error())
}
subscribers, err := subTx.ListActiveSubscribersForPackage(ctx, pkg.ID)
if err != nil {
return response.ErrInternal(50083, "kol_subscription_query_failed", err.Error())
}
for _, sub := range subscribers {
if err := subTx.CreateAccessRow(ctx, repository.CreateAccessRowInput{
TenantID: sub.TenantID,
SubscriptionID: sub.ID,
PackageID: pkg.ID,
PromptID: promptID,
}); err != nil {
return response.ErrInternal(50084, "kol_subscription_access_create_failed", err.Error())
}
}
if err := tx.Commit(ctx); err != nil {
return response.ErrInternal(50081, "kol_prompt_publish_commit_failed", err.Error())
}