From 97c18cdbeffdb43c3afd153469bbb13af5d152f2 Mon Sep 17 00:00:00 2001 From: liangxu Date: Fri, 17 Apr 2026 14:52:16 +0800 Subject: [PATCH] feat(kol): generation + schema HTTP endpoints --- .../transport/kol_marketplace_handler.go | 61 ++++++++++++++++++- server/internal/tenant/transport/router.go | 2 + 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/server/internal/tenant/transport/kol_marketplace_handler.go b/server/internal/tenant/transport/kol_marketplace_handler.go index 0c0be8b..0cfcd4b 100644 --- a/server/internal/tenant/transport/kol_marketplace_handler.go +++ b/server/internal/tenant/transport/kol_marketplace_handler.go @@ -8,15 +8,28 @@ import ( "github.com/geo-platform/tenant-api/internal/bootstrap" "github.com/geo-platform/tenant-api/internal/shared/response" "github.com/geo-platform/tenant-api/internal/tenant/app" + "github.com/geo-platform/tenant-api/internal/tenant/repository" ) type KolMarketplaceHandler struct { - svc *app.KolMarketplaceService + svc *app.KolMarketplaceService + genSvc *app.KolGenerationService } func NewKolMarketplaceHandler(a *bootstrap.App) *KolMarketplaceHandler { return &KolMarketplaceHandler{ svc: app.NewKolMarketplaceService(a.KolMarketplace, a.KolSubscriptions), + genSvc: app.NewKolGenerationService( + a.DB, + a.KolSubscriptions, + a.KolPrompts, + repository.NewKolUsageRepository(a.DB), + repository.NewArticleRepository(a.DB), + repository.NewAuditRepository(a.DB), + repository.NewQuotaRepository(a.DB), + a.KolPromptAsset, + a.RabbitMQ, + ).WithCache(a.Cache), } } @@ -112,6 +125,52 @@ func (h *KolMarketplaceHandler) ListSubscriptionPrompts(c *gin.Context) { response.Success(c, data) } +func (h *KolMarketplaceHandler) SubscriptionPromptSchema(c *gin.Context) { + id, ok := parseInt64Param(c, "id", "subscription prompt id") + if !ok { + return + } + + actor, ok := actorFromRequest(c) + if !ok { + return + } + + data, err := h.genSvc.GetSchema(c.Request.Context(), actor, id) + if err != nil { + response.Error(c, err) + return + } + + response.Success(c, data) +} + +func (h *KolMarketplaceHandler) Generate(c *gin.Context) { + id, ok := parseInt64Param(c, "id", "subscription prompt id") + if !ok { + return + } + + var req app.KolGenerationSubmitRequest + if err := c.ShouldBindJSON(&req); err != nil { + response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error())) + return + } + + actor, ok := actorFromRequest(c) + if !ok { + return + } + + data, err := h.genSvc.Submit(c.Request.Context(), actor, id, req.Variables) + if err != nil { + response.Error(c, err) + return + } + + response.Success(c, data) +} + func parseIntQuery(value string, fallback int) int { if value == "" { return fallback diff --git a/server/internal/tenant/transport/router.go b/server/internal/tenant/transport/router.go index 3d320cb..2db74dd 100644 --- a/server/internal/tenant/transport/router.go +++ b/server/internal/tenant/transport/router.go @@ -83,6 +83,8 @@ func RegisterRoutes(app *bootstrap.App) { kolSubscriptions := protected.Group("/tenant/kol") kolSubscriptions.GET("/subscriptions", kolMarketplaceHandler.ListSubscriptions) kolSubscriptions.GET("/subscription-prompts", kolMarketplaceHandler.ListSubscriptionPrompts) + kolSubscriptions.GET("/subscription-prompts/:id/schema", kolMarketplaceHandler.SubscriptionPromptSchema) + kolSubscriptions.POST("/subscription-prompts/:id/generate", kolMarketplaceHandler.Generate) // V1 compromise: these admin operations live on tenant-api and are gated by // tenant_role=tenant_admin until the platform-api/module is built.