refactor: 按go modules规范重构
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"knowledge-graph-backend/internal/service"
|
||||
)
|
||||
|
||||
type GraphHandler struct {
|
||||
service service.GraphService
|
||||
}
|
||||
|
||||
func NewGraphHandler(svc service.GraphService) *GraphHandler {
|
||||
return &GraphHandler{
|
||||
service: svc,
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 获取图数据
|
||||
// @Description 获取知识图谱的全部节点和边数据
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.GraphData "成功"
|
||||
// @Failure 500 {object} model.ErrorResponse "内部错误"
|
||||
// @Router /api/graph [get]
|
||||
func (h *GraphHandler) GetGraphData(c *gin.Context) {
|
||||
data := h.service.GetGraphData()
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
// @Summary 获取图统计信息
|
||||
// @Description 获取知识图谱的节点数、边数等统计信息
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]interface{} "成功"
|
||||
// @Failure 500 {object} model.ErrorResponse "内部错误"
|
||||
// @Router /api/graph/stats [get]
|
||||
func (h *GraphHandler) GetStats(c *gin.Context) {
|
||||
stats := h.service.GetStats()
|
||||
c.JSON(http.StatusOK, stats)
|
||||
}
|
||||
|
||||
// @Summary 获取简化图数据
|
||||
// @Description 获取知识图谱的全部节点和边数据(仅保留核心信息,适合LLM处理)
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.SimpleGraphData "成功"
|
||||
// @Failure 500 {object} model.ErrorResponse "内部错误"
|
||||
// @Router /api/graph/simpleJson [get]
|
||||
func (h *GraphHandler) GetSimpleGraphData(c *gin.Context) {
|
||||
data := h.service.GetSimpleGraphData()
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
Reference in New Issue
Block a user