Feat: 实现知识图谱数据库的检索方法,并对外提供接口

This commit is contained in:
2026-04-13 15:21:54 +08:00
parent 6764095ed1
commit 258e5d21f9
8 changed files with 339 additions and 277 deletions
+5 -5
View File
@@ -8,22 +8,22 @@ import (
)
type GraphHandler struct {
dataService *services.DataService
service services.GraphService
}
func NewGraphHandler(dataService *services.DataService) *GraphHandler {
func NewGraphHandler(service services.GraphService) *GraphHandler {
return &GraphHandler{
dataService: dataService,
service: service,
}
}
func (h *GraphHandler) GetGraphData(c *gin.Context) {
data := h.dataService.GetGraphData()
data := h.service.GetGraphData()
c.JSON(http.StatusOK, data)
}
func (h *GraphHandler) GetStats(c *gin.Context) {
stats := h.dataService.GetStats()
stats := h.service.GetStats()
c.JSON(http.StatusOK, gin.H{
"stats": stats,
"timestamp": gin.H{
+5 -5
View File
@@ -8,12 +8,12 @@ import (
)
type NodeHandler struct {
dataService *services.DataService
service services.GraphService
}
func NewNodeHandler(dataService *services.DataService) *NodeHandler {
func NewNodeHandler(service services.GraphService) *NodeHandler {
return &NodeHandler{
dataService: dataService,
service: service,
}
}
@@ -27,7 +27,7 @@ func (h *NodeHandler) GetNodeByID(c *gin.Context) {
return
}
node, found := h.dataService.GetNodeByID(nodeID)
node, found := h.service.GetNodeByID(nodeID)
if !found {
c.JSON(http.StatusNotFound, gin.H{
"error": "Not Found",
@@ -49,7 +49,7 @@ func (h *NodeHandler) GetNeighbors(c *gin.Context) {
return
}
neighbors, found := h.dataService.GetNeighbors(nodeID)
neighbors, found := h.service.GetNeighbors(nodeID)
if !found {
c.JSON(http.StatusNotFound, gin.H{
"error": "Not Found",
+4 -4
View File
@@ -8,12 +8,12 @@ import (
)
type SearchHandler struct {
dataService *services.DataService
service services.GraphService
}
func NewSearchHandler(dataService *services.DataService) *SearchHandler {
func NewSearchHandler(service services.GraphService) *SearchHandler {
return &SearchHandler{
dataService: dataService,
service: service,
}
}
@@ -27,7 +27,7 @@ func (h *SearchHandler) SearchNodes(c *gin.Context) {
return
}
results := h.dataService.SearchNodes(query)
results := h.service.SearchNodes(query)
c.JSON(http.StatusOK, results)
}