feat: 编写swagger注释并生成文档
This commit is contained in:
@@ -17,11 +17,23 @@ func NewGraphHandler(service services.GraphService) *GraphHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 获取图数据
|
||||
// @Description 获取知识图谱的全部节点和边数据
|
||||
// @Produce json
|
||||
// @Success 200 {object} models.GraphData "成功"
|
||||
// @Failure 500 {object} models.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} models.ErrorResponse "内部错误"
|
||||
// @Router /api/graph/stats [get]
|
||||
func (h *GraphHandler) GetStats(c *gin.Context) {
|
||||
stats := h.service.GetStats()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
@@ -17,6 +17,15 @@ func NewNodeHandler(service services.GraphService) *NodeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 获取节点详情
|
||||
// @Description 根据节点 ID 获取知识图谱中的节点详细信息
|
||||
// @Produce json
|
||||
// @Param id path string true "节点 ID"
|
||||
// @Success 200 {object} models.NodeResponse "成功"
|
||||
// @Failure 400 {object} models.ErrorResponse "请求错误"
|
||||
// @Failure 404 {object} models.ErrorResponse "节点未找到"
|
||||
// @Failure 500 {object} models.ErrorResponse "内部错误"
|
||||
// @Router /api/nodes/{id} [get]
|
||||
func (h *NodeHandler) GetNodeByID(c *gin.Context) {
|
||||
nodeID := c.Param("id")
|
||||
if nodeID == "" {
|
||||
@@ -39,6 +48,15 @@ func (h *NodeHandler) GetNodeByID(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, node)
|
||||
}
|
||||
|
||||
// @Summary 获取节点邻居
|
||||
// @Description 根据节点 ID 获取其所有邻居节点及关联边
|
||||
// @Produce json
|
||||
// @Param id path string true "节点 ID"
|
||||
// @Success 200 {object} models.NeighborResponse "成功"
|
||||
// @Failure 400 {object} models.ErrorResponse "请求错误"
|
||||
// @Failure 404 {object} models.ErrorResponse "节点未找到"
|
||||
// @Failure 500 {object} models.ErrorResponse "内部错误"
|
||||
// @Router /api/nodes/{id}/neighbors [get]
|
||||
func (h *NodeHandler) GetNeighbors(c *gin.Context) {
|
||||
nodeID := c.Param("id")
|
||||
if nodeID == "" {
|
||||
|
||||
@@ -17,6 +17,14 @@ func NewSearchHandler(service services.GraphService) *SearchHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// @Summary 搜索节点
|
||||
// @Description 根据关键词搜索知识图谱中的节点
|
||||
// @Produce json
|
||||
// @Param q query string true "搜索关键词"
|
||||
// @Success 200 {object} models.SearchResponse "成功"
|
||||
// @Failure 400 {object} models.ErrorResponse "请求错误"
|
||||
// @Failure 500 {object} models.ErrorResponse "内部错误"
|
||||
// @Router /api/search [get]
|
||||
func (h *SearchHandler) SearchNodes(c *gin.Context) {
|
||||
query := c.Query("q")
|
||||
if query == "" {
|
||||
|
||||
Reference in New Issue
Block a user