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