feat(kol): generation + schema HTTP endpoints
This commit is contained in:
@@ -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
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user