Files
knowledge-graph-agent/backend/handlers/graph_handler.go
T

35 lines
643 B
Go
Raw Normal View History

2026-04-05 15:03:56 +08:00
package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
"knowledge-graph-backend/services"
)
type GraphHandler struct {
service services.GraphService
2026-04-05 15:03:56 +08:00
}
func NewGraphHandler(service services.GraphService) *GraphHandler {
2026-04-05 15:03:56 +08:00
return &GraphHandler{
service: service,
2026-04-05 15:03:56 +08:00
}
}
func (h *GraphHandler) GetGraphData(c *gin.Context) {
data := h.service.GetGraphData()
2026-04-05 15:03:56 +08:00
c.JSON(http.StatusOK, data)
}
func (h *GraphHandler) GetStats(c *gin.Context) {
stats := h.service.GetStats()
2026-04-05 15:03:56 +08:00
c.JSON(http.StatusOK, gin.H{
"stats": stats,
"timestamp": gin.H{
"totalNodes": stats["totalNodes"],
"totalEdges": stats["totalEdges"],
},
})
}