35 lines
667 B
Go
35 lines
667 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"knowledge-graph-backend/services"
|
|
)
|
|
|
|
type GraphHandler struct {
|
|
dataService *services.DataService
|
|
}
|
|
|
|
func NewGraphHandler(dataService *services.DataService) *GraphHandler {
|
|
return &GraphHandler{
|
|
dataService: dataService,
|
|
}
|
|
}
|
|
|
|
func (h *GraphHandler) GetGraphData(c *gin.Context) {
|
|
data := h.dataService.GetGraphData()
|
|
c.JSON(http.StatusOK, data)
|
|
}
|
|
|
|
func (h *GraphHandler) GetStats(c *gin.Context) {
|
|
stats := h.dataService.GetStats()
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"stats": stats,
|
|
"timestamp": gin.H{
|
|
"totalNodes": stats["totalNodes"],
|
|
"totalEdges": stats["totalEdges"],
|
|
},
|
|
})
|
|
}
|