From ccf0706023f91d83085ae157029cde7e0fc38dc1 Mon Sep 17 00:00:00 2001 From: Fantasy lee <129943055+Fantasylee21@users.noreply.github.com> Date: Tue, 27 May 2025 21:32:34 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:=20=E5=AE=8C=E6=88=90=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E7=BB=BC=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/aichat.py | 11 +++++++---- app/curd/note.py | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/api/v1/endpoints/aichat.py b/app/api/v1/endpoints/aichat.py index e9dd4a6..468e014 100644 --- a/app/api/v1/endpoints/aichat.py +++ b/app/api/v1/endpoints/aichat.py @@ -79,15 +79,18 @@ async def ai_stream(): @router.get("/graph", response_model=dict) async def generate_graph( - note_id: int, + article_id: int, db : AsyncSession = Depends(get_db), ): # 读取数据库获取笔记内容 from app.curd.note import get_note_by_id - note = await get_note_by_id(db, note_id) - if not note: + notes = await get_note_by_id(db, article_id) + if not notes: raise HTTPException(status_code=404, detail="Note not found") - text = note.content + text = f"以下是关于文章ID {article_id} 的笔记内容:\n\n" + for note in notes: + text += f"标题: {note.title}\n" if note.title else "" + text += note.content if note.content else "" text += """ 我需要你对于上面的内容生成思维导图,请仅给我返回mermaid代码,不要有其他内容,下面是生成样例, graph TD diff --git a/app/curd/note.py b/app/curd/note.py index ac4b8ee..c751a61 100644 --- a/app/curd/note.py +++ b/app/curd/note.py @@ -181,10 +181,12 @@ async def find_self_notes_count_in_db(db: AsyncSession, user_id: int): count = result.scalar_one_or_none() return count -async def get_note_by_id(db: AsyncSession, note_id: int): +async def get_note_by_id(db: AsyncSession, article_id: int): """ 根据 ID 获取笔记 """ - stmt = select(Note).where(Note.id == note_id, Note.visible == True) + stmt = select(Note).where(Note.article_id == article_id and Note.visible == True) result = await db.execute(stmt) - return result.scalar_one_or_none() # 返回单个笔记或 None \ No newline at end of file + # 返回所有笔记 + notes = result.scalars().all() + return notes if notes else None \ No newline at end of file