package handler import ( "github.com/Tencent/WeKnora/internal/application/service" werrors "github.com/Tencent/WeKnora/internal/errors" "github.com/gin-gonic/gin" ) type KnowledgeClassificationHandler struct { service *service.KnowledgeClassificationService } func NewKnowledgeClassificationHandler(s *service.KnowledgeClassificationService) *KnowledgeClassificationHandler { return &KnowledgeClassificationHandler{service: s} } func (h *KnowledgeClassificationHandler) List(c *gin.Context) { data, e := h.service.List(c.Request.Context(), c.Param("id")) if e != nil { c.Error(service.KnowledgeClassificationPublicError(e)) return } c.JSON(200, gin.H{"success": true, "data": data}) } func (h *KnowledgeClassificationHandler) Create(c *gin.Context) { var input struct { ModelID string `json:"model_id"` KnowledgeIDs []string `json:"knowledge_ids"` } if e := c.ShouldBindJSON(&input); e != nil { c.Error(werrors.NewBadRequestError("分类请求格式有误")) return } data, e := h.service.Create(c.Request.Context(), c.Param("id"), input.ModelID, input.KnowledgeIDs) if e != nil { c.Error(service.KnowledgeClassificationPublicError(e)) return } c.JSON(202, gin.H{"success": true, "data": data}) } func (h *KnowledgeClassificationHandler) Apply(c *gin.Context) { var input struct { ItemIDs []string `json:"item_ids"` } if e := c.ShouldBindJSON(&input); e != nil { c.Error(werrors.NewBadRequestError("请选择需要采用的分类建议")) return } if e := h.service.Apply(c.Request.Context(), c.Param("id"), c.Param("job_id"), input.ItemIDs); e != nil { c.Error(service.KnowledgeClassificationPublicError(e)) return } c.JSON(200, gin.H{"success": true}) } func (h *KnowledgeClassificationHandler) Retry(c *gin.Context) { if e := h.service.Retry(c.Request.Context(), c.Param("id"), c.Param("job_id")); e != nil { c.Error(service.KnowledgeClassificationPublicError(e)) return } c.JSON(202, gin.H{"success": true}) }