Files
geo/server/internal/tenant/transport/kol_admin_handler.go
T
root b2605abd6a feat: Enhance Kol Generation Service with web search and knowledge group support
- Added `EnableWebSearch` and `KnowledgeGroupIDs` fields to `KolGenerationSubmitRequest`.
- Updated `Submit` method in `KolGenerationService` to handle new request fields.
- Integrated web search and knowledge group validation based on card configuration.
- Introduced caching mechanisms in `KolPackageService`, `KolPromptService`, and `KolSubscriptionAdminService` to improve performance.
- Implemented knowledge context resolution in `KolGenerationWorker` to enrich prompts with relevant knowledge snippets.
- Added utility functions for handling card configuration in both backend and frontend.
- Created tests for knowledge extraction and rendering to ensure accuracy and reliability.
2026-04-18 13:47:32 +08:00

117 lines
2.6 KiB
Go

package transport
import (
"time"
"github.com/gin-gonic/gin"
"github.com/geo-platform/tenant-api/internal/bootstrap"
"github.com/geo-platform/tenant-api/internal/shared/auth"
"github.com/geo-platform/tenant-api/internal/shared/response"
"github.com/geo-platform/tenant-api/internal/tenant/app"
)
var errTenantAdminRequired = response.ErrForbidden(40371, "tenant_admin_required", "tenant admin role is required")
type KolAdminHandler struct {
svc *app.KolSubscriptionAdminService
}
type approveKolSubscriptionRequest struct {
EndAt *time.Time `json:"end_at"`
}
func NewKolAdminHandler(a *bootstrap.App) *KolAdminHandler {
return &KolAdminHandler{
svc: app.NewKolSubscriptionAdminService(
a.DB,
a.AuditLogs,
a.KolMarketplace,
a.KolSubscriptions,
a.KolPrompts,
).WithCache(a.Cache),
}
}
func (h *KolAdminHandler) ApproveSubscription(c *gin.Context) {
id, ok := parseInt64Param(c, "id", "subscription id")
if !ok {
return
}
actor, ok := requireTenantAdmin(c)
if !ok {
return
}
var req approveKolSubscriptionRequest
if c.Request.ContentLength > 0 {
if err := c.ShouldBindJSON(&req); err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
return
}
}
data, err := h.svc.Approve(c.Request.Context(), id, req.EndAt, actor.UserID)
if err != nil {
response.Error(c, err)
return
}
response.Success(c, data)
}
func (h *KolAdminHandler) ManualBind(c *gin.Context) {
actor, ok := requireTenantAdmin(c)
if !ok {
return
}
var req app.ManualBindKolSubscriptionInput
if err := c.ShouldBindJSON(&req); err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
return
}
data, err := h.svc.ManualBind(c.Request.Context(), req, actor.UserID)
if err != nil {
response.Error(c, err)
return
}
response.Success(c, data)
}
func (h *KolAdminHandler) RevokeSubscription(c *gin.Context) {
id, ok := parseInt64Param(c, "id", "subscription id")
if !ok {
return
}
actor, ok := requireTenantAdmin(c)
if !ok {
return
}
if err := h.svc.Revoke(c.Request.Context(), id, actor.UserID); err != nil {
response.Error(c, err)
return
}
response.Success(c, gin.H{"ok": true})
}
// V1 compromise: these admin endpoints live on tenant-api until a dedicated
// platform-api/module exists. The temporary gate is tenant_role=tenant_admin.
func requireTenantAdmin(c *gin.Context) (auth.Actor, bool) {
actor, ok := actorFromRequest(c)
if !ok {
return auth.Actor{}, false
}
if actor.Role != "tenant_admin" {
response.Error(c, errTenantAdminRequired)
return auth.Actor{}, false
}
return actor, true
}