2026-05-12 21:53:36 +08:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 15:59:39 +08:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 21:53:36 +08:00
|
|
|
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
|
|
|
|
|
}
|