Files

30 lines
947 B
Go
Raw Permalink Normal View History

package handler
import (
"github.com/Tencent/WeKnora/internal/application/repository/retriever/legacygraph"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
type NativeGraphHandler struct{ repo *legacygraph.Repository }
func NewNativeGraphHandler(repo *legacygraph.Repository) *NativeGraphHandler {
return &NativeGraphHandler{repo: repo}
}
func (h *NativeGraphHandler) Browse(c *gin.Context) {
cursor, _ := strconv.ParseInt(c.Query("cursor"), 10, 64)
entity, _ := strconv.ParseInt(c.Query("entity"), 10, 64)
query := c.Query("q")
if len([]rune(query)) > 200 {
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "查询过长"})
return
}
data, err := h.repo.Browse(c.Request.Context(), c.Param("id"), query, cursor, entity)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": "图谱读取失败"})
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": data})
}