From c84b36ca523ebe6a08c0e3df7f52fb130bf77efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E6=98=95=E7=9D=BF?= <22371298@buaa.edu.cn> Date: Fri, 6 Jun 2025 17:05:31 +0800 Subject: [PATCH] =?UTF-8?q?[fix]:=20=E4=BF=AE=E5=A4=8D=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=86=85=E5=AE=B9=E9=95=BF=E5=BA=A6=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/endpoints/group.py | 2 +- app/api/v1/endpoints/note.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/api/v1/endpoints/group.py b/app/api/v1/endpoints/group.py index 59f2e90..ad93b33 100644 --- a/app/api/v1/endpoints/group.py +++ b/app/api/v1/endpoints/group.py @@ -240,7 +240,7 @@ async def change_article_name(article_id: int = Body(...), article_name: str = B @router.post("/changeNote", response_model=dict) async def change_note(note_id: int = Body(...), note_title: Optional[str] = Body(default=None), note_content: Optional[str] = Body(default=None), db: AsyncSession = Depends(get_db), user: dict = Depends(get_current_user)): - if len(note_title) > 100: + if note_title and len(note_title) > 100: raise HTTPException(status_code=405, detail="Invalid note title, longer than 100") user_id = user.get("id") await crud_change_note(user_id, note_id, note_title, note_content, db) diff --git a/app/api/v1/endpoints/note.py b/app/api/v1/endpoints/note.py index 8693925..8fc2def 100644 --- a/app/api/v1/endpoints/note.py +++ b/app/api/v1/endpoints/note.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException, Depends +from fastapi import APIRouter, HTTPException, Depends, Body from sqlalchemy.ext.asyncio import AsyncSession from app.schemas.note import NoteCreate, NoteUpdate, NoteFind from app.utils.get_db import get_db @@ -21,8 +21,8 @@ async def delete_note(note_id: int, db: AsyncSession = Depends(get_db), current_ raise HTTPException(status_code=404, detail="Note not found") return {"msg": "Note deleted successfully"} -@router.put("/{note_id}", response_model=dict) -async def update_note(note_id: int, content: Optional[str] = None, title: Optional[str] = None,db: AsyncSession = Depends(get_db)): +@router.post("/{note_id}", response_model=dict) +async def update_note(note_id: int, content: Optional[str] = Body(default=None), title: Optional[str] = Body(default=None), db: AsyncSession = Depends(get_db)): if content is None and title is None: raise HTTPException(status_code=400, detail="At least one field must be provided for update") note = NoteUpdate(id=note_id, content=content, title=title)