1eae6fb6d4
- add /questions/combination-fill endpoint with AI-driven, IP-region-aware matrix fill - extract ip2region resolver from ops/app into shared/ipregion for cross-service use - thread question_id filter through dashboard composite, citation summary, and collect-now - switch template wizard from keyword inputs to brand-question selection (primary + supplemental) - pass brand_question and supplemental_questions through assist/title/outline prompts - add AiWaitingModal + 45s client timeout and request_timeout error mapping for long AI flows Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
3.1 KiB
Go
121 lines
3.1 KiB
Go
package transport
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"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"
|
|
)
|
|
|
|
type QuestionExpansionHandler struct {
|
|
svc *app.QuestionExpansionService
|
|
}
|
|
|
|
func NewQuestionExpansionHandler(a *bootstrap.App) *QuestionExpansionHandler {
|
|
return &QuestionExpansionHandler{svc: a.QuestionExpansion}
|
|
}
|
|
|
|
func (h *QuestionExpansionHandler) CombinationPreview(c *gin.Context) {
|
|
brandID, ok := parseBrandIDParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req app.QuestionCombinationRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
data, err := h.svc.GenerateByCombination(c.Request.Context(), brandID, req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *QuestionExpansionHandler) CombinationFill(c *gin.Context) {
|
|
brandID, ok := parseBrandIDParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req app.QuestionCombinationFillRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
data, err := h.svc.FillQuestionCombination(c.Request.Context(), brandID, c.ClientIP(), req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *QuestionExpansionHandler) AIDistill(c *gin.Context) {
|
|
brandID, ok := parseBrandIDParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req app.QuestionDistillRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
data, err := h.svc.GenerateByAIDistill(c.Request.Context(), brandID, req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *QuestionExpansionHandler) ClassifyMetadata(c *gin.Context) {
|
|
brandID, ok := parseBrandIDParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req struct {
|
|
Texts []string `json:"texts" binding:"required,min=1"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
data, err := h.svc.ClassifyMetadata(c.Request.Context(), brandID, req.Texts)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func (h *QuestionExpansionHandler) Materialize(c *gin.Context) {
|
|
brandID, ok := parseBrandIDParam(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req app.MaterializeQuestionsRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
|
return
|
|
}
|
|
data, err := h.svc.MaterializeQuestions(c.Request.Context(), brandID, req)
|
|
if err != nil {
|
|
response.Error(c, err)
|
|
return
|
|
}
|
|
response.Success(c, data)
|
|
}
|
|
|
|
func parseBrandIDParam(c *gin.Context) (int64, bool) {
|
|
brandID, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
|
if err != nil || brandID <= 0 {
|
|
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "brand id must be a number"))
|
|
return 0, false
|
|
}
|
|
return brandID, true
|
|
}
|