|
|
|
@ -209,5 +209,35 @@ async def get_tree_data():
|
|
|
|
|
return {"code": 1, "msg": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/api/update-prerequisites")
|
|
|
|
|
async def update_prerequisites(request: fastapi.Request):
|
|
|
|
|
try:
|
|
|
|
|
data = await request.json()
|
|
|
|
|
node_id = data.get('node_id')
|
|
|
|
|
prerequisites = data.get('prerequisites', [])
|
|
|
|
|
|
|
|
|
|
if not node_id:
|
|
|
|
|
raise ValueError("Missing node_id")
|
|
|
|
|
|
|
|
|
|
mysql_pool = await init_mysql_pool()
|
|
|
|
|
async with mysql_pool.acquire() as conn:
|
|
|
|
|
await conn.ping()
|
|
|
|
|
async with conn.cursor() as cur:
|
|
|
|
|
await cur.execute(
|
|
|
|
|
"""
|
|
|
|
|
UPDATE knowledge_points
|
|
|
|
|
SET prerequisite = %s
|
|
|
|
|
WHERE id = %s
|
|
|
|
|
""",
|
|
|
|
|
(json.dumps([{"id": p["id"], "title": p["title"]} for p in prerequisites]), node_id)
|
|
|
|
|
)
|
|
|
|
|
await conn.commit()
|
|
|
|
|
|
|
|
|
|
return {"code": 0, "msg": "更新成功"}
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"更新先修知识失败: {str(e)}")
|
|
|
|
|
return {"code": 1, "msg": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
|