feat: 增加对neo4j的增改查

This commit is contained in:
2026-04-15 14:24:39 +08:00
parent c9643db67e
commit 37cd2171b1
11 changed files with 2148 additions and 348 deletions
+398
View File
@@ -15,6 +15,99 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/edges": {
"post": {
"description": "在知识图谱中创建一个新边(关系)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "创建边",
"parameters": [
{
"description": "边创建请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.CreateEdgeRequest"
}
}
],
"responses": {
"200": {
"description": "创建成功",
"schema": {
"$ref": "#/definitions/models.EdgeResponse"
}
},
"400": {
"description": "请求错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "源节点或目标节点未找到",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"409": {
"description": "边已存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/edges/{id}": {
"delete": {
"description": "从知识图谱中删除指定的边",
"produces": [
"application/json"
],
"summary": "删除边",
"parameters": [
{
"type": "string",
"description": "边ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/models.DeleteResponse"
}
},
"404": {
"description": "边未找到",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/graph": {
"get": {
"description": "获取知识图谱的全部节点和边数据",
@@ -62,6 +155,55 @@ const docTemplate = `{
}
}
},
"/api/nodes": {
"post": {
"description": "在知识图谱中创建一个新节点",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "创建节点",
"parameters": [
{
"description": "节点创建请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.CreateNodeRequest"
}
}
],
"responses": {
"200": {
"description": "创建成功",
"schema": {
"$ref": "#/definitions/models.Node"
}
},
"400": {
"description": "请求错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"409": {
"description": "节点已存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/nodes/{id}": {
"get": {
"description": "根据节点 ID 获取知识图谱中的节点详细信息",
@@ -104,6 +246,96 @@ const docTemplate = `{
}
}
}
},
"put": {
"description": "更新知识图谱中指定节点的信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "更新节点",
"parameters": [
{
"type": "string",
"description": "节点ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "节点更新请求",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.UpdateNodeRequest"
}
}
],
"responses": {
"200": {
"description": "更新成功",
"schema": {
"$ref": "#/definitions/models.Node"
}
},
"400": {
"description": "请求错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "节点未找到",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"delete": {
"description": "从知识图谱中删除指定节点及其相关的所有边",
"produces": [
"application/json"
],
"summary": "删除节点",
"parameters": [
{
"type": "string",
"description": "节点ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/models.DeleteResponse"
}
},
"404": {
"description": "节点未找到",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/nodes/{id}/neighbors": {
@@ -190,6 +422,107 @@ const docTemplate = `{
}
},
"definitions": {
"models.CreateEdgeRequest": {
"type": "object",
"required": [
"id",
"label",
"source",
"target"
],
"properties": {
"id": {
"description": "边的唯一标识",
"type": "string",
"example": "edge_123"
},
"label": {
"description": "边的显示标签",
"type": "string",
"example": "包含"
},
"properties": {
"description": "自定义属性",
"type": "object",
"additionalProperties": true
},
"source": {
"description": "源节点ID",
"type": "string",
"example": "node_1"
},
"target": {
"description": "目标节点ID",
"type": "string",
"example": "node_2"
},
"type": {
"description": "边的类型(可选,默认为关系类型)",
"type": "string",
"example": "CONTAINS"
}
}
},
"models.CreateNodeRequest": {
"type": "object",
"required": [
"id",
"label",
"type"
],
"properties": {
"id": {
"description": "节点唯一标识",
"type": "string",
"example": "node_123"
},
"label": {
"description": "节点显示标签",
"type": "string",
"example": "人工智能"
},
"properties": {
"description": "自定义属性",
"type": "object",
"additionalProperties": true
},
"type": {
"description": "节点类型",
"type": "string",
"example": "概念"
},
"x": {
"description": "X坐标(可选)",
"type": "number",
"example": 100
},
"y": {
"description": "Y坐标(可选)",
"type": "number",
"example": 200
}
}
},
"models.DeleteResponse": {
"type": "object",
"properties": {
"id": {
"description": "被删除的实体ID(可选)",
"type": "string",
"example": "node_123"
},
"message": {
"description": "消息",
"type": "string",
"example": "节点已成功删除"
},
"success": {
"description": "是否成功",
"type": "boolean",
"example": true
}
}
},
"models.Edge": {
"type": "object",
"properties": {
@@ -218,6 +551,41 @@ const docTemplate = `{
}
}
},
"models.EdgeResponse": {
"type": "object",
"properties": {
"id": {
"description": "边的ID",
"type": "string",
"example": "edge_123"
},
"label": {
"description": "边的显示标签",
"type": "string",
"example": "包含"
},
"properties": {
"description": "自定义属性",
"type": "object",
"additionalProperties": true
},
"source": {
"description": "源节点ID",
"type": "string",
"example": "node_1"
},
"target": {
"description": "目标节点ID",
"type": "string",
"example": "node_2"
},
"type": {
"description": "边的类型",
"type": "string",
"example": "CONTAINS"
}
}
},
"models.ErrorResponse": {
"type": "object",
"properties": {
@@ -325,6 +693,36 @@ const docTemplate = `{
}
}
}
},
"models.UpdateNodeRequest": {
"type": "object",
"properties": {
"label": {
"description": "节点显示标签",
"type": "string",
"example": "机器学习"
},
"properties": {
"description": "自定义属性(更新)",
"type": "object",
"additionalProperties": true
},
"type": {
"description": "节点类型",
"type": "string",
"example": "工具"
},
"x": {
"description": "X坐标",
"type": "number",
"example": 150
},
"y": {
"description": "Y坐标",
"type": "number",
"example": 250
}
}
}
}
}`