refactor: 重构neo4j服务

This commit is contained in:
2026-04-28 12:53:01 +08:00
parent 3ff8f3951a
commit f998f78c80
10 changed files with 654 additions and 795 deletions
+5 -16
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"knowledge-graph-backend/internal/model"
"knowledge-graph-backend/internal/service"
)
@@ -29,19 +30,13 @@ func NewNodeHandler(svc service.GraphService) *NodeHandler {
func (h *NodeHandler) GetNodeByID(c *gin.Context) {
nodeID := c.Param("id")
if nodeID == "" {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Bad Request",
"message": "Node ID is required",
})
c.JSON(http.StatusBadRequest, model.ErrorResponse{Error: "bad_request", Message: "Node ID is required"})
return
}
node, found := h.service.GetNodeByID(nodeID)
if !found {
c.JSON(http.StatusNotFound, gin.H{
"error": "Not Found",
"message": "Node with ID '" + nodeID + "' not found",
})
c.JSON(http.StatusNotFound, model.ErrorResponse{Error: "not_found", Message: "Node with ID '" + nodeID + "' not found"})
return
}
@@ -60,19 +55,13 @@ func (h *NodeHandler) GetNodeByID(c *gin.Context) {
func (h *NodeHandler) GetNeighbors(c *gin.Context) {
nodeID := c.Param("id")
if nodeID == "" {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Bad Request",
"message": "Node ID is required",
})
c.JSON(http.StatusBadRequest, model.ErrorResponse{Error: "bad_request", Message: "Node ID is required"})
return
}
neighbors, found := h.service.GetNeighbors(nodeID)
if !found {
c.JSON(http.StatusNotFound, gin.H{
"error": "Not Found",
"message": "Node with ID '" + nodeID + "' not found",
})
c.JSON(http.StatusNotFound, model.ErrorResponse{Error: "not_found", Message: "Node with ID '" + nodeID + "' not found"})
return
}